0

我想我在某个地方有一个简单的错误,但我看不到它!在我看来,我有以下 javascript 来创建表单:

  $.ajax({
    url:"<?php echo site_url('mycontroller/methodX/'.$ip.'/'.$hardwaremodel);?>",
    type:'POST',
    dataType:'json',
    success: function(returnDataFromController) {
    var htmlstring;
    var submitFormHTML;
    htmlstring = "<br><br><B>To reassign the port to a new vlan, click on a VlanId below and then click on the OK button</B><br><table class='table table-bordered table-striped'>";
    htmlstring = htmlstring + "<th>VlanId</th><th>Name</th>";
    for(i = 0; i < returnDataFromController.length; i++) {

    }
    submitFormHTML = "<form method='post' accept-charset='utf-8' action='/myapp/index.php/controllerABC/methodABC/"+ $('#ip').val() +"/" + $('#hardwaremodel').val() +"/" + $('#port').val() + "'><input type='text' id='newVlanID' style='width:5em;height:1.5em'/>&nbsp;&nbsp;<button type='submit' class='btn' id='saveVlan' style='width:10em;height:2em'>Reassign Vlan</button></form>";
    //alert(submitFormHTML);
    $('#clientajaxcontainer').html(htmlstring);
    $('#newvlanform').html(submitFormHTML);

它是构建表单的“submitFormHTML”字符串。

在我的控制器中,我有以下逻辑来检查输入: public function methodABC() {

     if($_POST){
         echo 'I am here';
         $form = $this->input->post();
         var_dump($form);
         exit();
     }
     else {
         echo "false";
     }

它总是打印“假”。我也尝试过使用:

print_r($this->input->post());

    echo $this->input->post('newID');

但我似乎无法将数据从我的视图中获取到控制器中。你能看出我哪里错了吗?谢谢您的帮助。

编辑:

呈现页面时,会为表单创建以下 HTML:

<form method="post" action="/myapp/index.php/switches/changeportvlan/11.11.11.11 /">
<input type='text' id='newVlanID' style='width:5em;height:1.5em'/>&nbsp;&nbsp;
<button type="submit" class='btn' id='saveVlan' style='width:10em;height:2em'>Reassign Vlan</button>
</form>"
4

2 回答 2

3

问题是文本框缺少“名称”属性。“身份证”还不够!

于 2012-09-06T20:18:38.077 回答
0

你需要

if ($this->input->post(Null, False)) {
   echo "I am here";
   $form = $this->input->post(Null, True); ## True for XSS-cleaning, which you probably want.
   exit();
}
else {
   echo "False";
}

你必须给出$this->input->post()论据。此外,永远不要$_POST在 CodeIgniter 中使用。

祝你好运

于 2012-09-06T17:08:08.087 回答