表单操作在 codeigniter 中不起作用

Posted

技术标签:

【中文标题】表单操作在 codeigniter 中不起作用【英文标题】:Form action not working in codeigniter 【发布时间】:2014-12-01 16:58:05 【问题描述】:

在我的一种观点中,表单动作突然停止工作。当我点击提交页面时保持不变。但我在同一域上的其他表单工作正常。那么这个表格有什么问题呢?? 我在codeigniter中这样做。那么这背后的原因可能是什么?

 <form enctype="multipart/form-data" method="POST" action=<?php echo base_url()."index.php/controller_user/checker"; ?>  >
  <table  border="0" >
    <tr>
      <td>
        <table>
          <tr>
            <td>
              <div id="prj" style="display: none;">Enter Project:-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input  type="text" name="prname" required/>
              </div>
              <div id="project">Enter Project:-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                <select class="prj_name" name="prj_name" id="prj_name" onchange="process(this.value)" tabindex="11" required>
                  <option selected="selected">Select Project</option>
                  <?php
                    $sql = "SELECT * FROM project  ORDER BY prj_id DESC";
                    $query = $this->db->query($sql);
                    if ($query->num_rows() > 0)
                      foreach ($query->result() as $row)
                        $projectName= $row->prj_name;
                        $projectID=$row->prj_id;
                        echo '<option value="'.$projectID.'">'.$projectName.'</option>';
                      //end of for loop
                      echo '<option value="'.'0'.'">'.'New Project'.'</option>';
                     
                  ?>
                </select>
              </div>
            </td>
          </tr>
          <tr>
            <td>
              <input type="submit" name="submit" value="Submit"/>
            </td>
          </tr>
        </table>
</form>

这是我的控制器用户/检查器

  function checker()
   

   $projectname=$_POST['prj_name'];

        if($projectname=='0')
        
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = '*';
            $config['max_size'] = '100';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';
            $this->load->library('upload', $config);
            $this->upload->do_upload('layout');
            $data = $this->upload->data();
            move_uploaded_file($_FILES["layout1"]["tmp_name"],"uploads/" . $_FILES["layout1"]
  ["name"]);
            $file="uploads/".$_FILES["layout1"]["name"];
            $this->model_user->add_user_case1($file);

        
        else
         
            $phase_name=$_POST['phase_name'];
            //$layout=$_POST['layout'];
             if($phase_name=='0') 
             
                $config['upload_path'] = './uploads/';
            $config['allowed_types'] = '*';
            $config['max_size'] = '100';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';
            $this->load->library('upload', $config);
            $this->upload->do_upload('layout');
            $data = $this->upload->data();
            move_uploaded_file($_FILES["layout"]["tmp_name"],"uploads/" . $_FILES["layout"

    ]["name"]);
            $file="uploads/".$_FILES["layout"]["name"];

  /*$sql=$this->db->query("INSERT INTO phase (layout) VALUES ('$file')");*/
                $this->model_user->add_user_case2($projectname,$file);

             
             else
             
                 $plan_name=$_POST['plan_name'];

                if($plan_name=='0' )
                



                    $this->model_user->add_user_case3($phase_name);

                
                else
                    $this->model_user->add_user_case4($plan_name);

                
             

        

         echo '<script>alert("data registered successfully");</script>';
        redirect ('controller_search','refresh');

     

【问题讨论】:

你能显示controller_user/checker代码吗? 这不是我所有的表单代码,我只是复制粘贴其中的一部分来解释 @LLL 看我上面的编辑 请检查此表单之前是否有任何其他表单标签,并检查表单标签是否正确关闭 我觉得你可以用error_log在开始checker方法写post log,为什么不用ci输入$this-&gt;input-&gt;post()呢? 【参考方案1】:

问题来了

<div id="prj" style="display: none;">

去掉 display none 试试看,里面显示none

<input  type="text" name="prname" required/>

required 的文本字段,因此它验证表单并且不允许表单提交

<form enctype="multipart/form-data" method="POST" action=<?php echo base_url()."index.php/controller_user/checker"; ?>  >
  <table  border="0" >
    <tr>
      <td>
        <table>
          <tr>
            <td>
              <div id="prj" >Enter Project:-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input  type="text" name="prname" required/>
              </div>
              <div id="project">Enter Project:-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                <select class="prj_name" name="prj_name" id="prj_name" onchange="process(this.value)" tabindex="11" required>
                  <option selected="selected">Select Project</option>
                <?php
                    $sql = "SELECT * FROM project  ORDER BY prj_id DESC";
                    $query = $this->db->query($sql);
                    if ($query->num_rows() > 0)
                      foreach ($query->result() as $row)
                        $projectName= $row->prj_name;
                        $projectID=$row->prj_id;
                        echo '<option value="'.$projectID.'">'.$projectName.'</option>';
                      //end of for loop
                      echo '<option value="'.'0'.'">'.'New Project'.'</option>';
                     
                  ?>
                </select>
              </div>
            </td>
          </tr>
          <tr>
            <td>
              <input type="submit" name="submit" value="Submit"/>
            </td>
          </tr>
        </table>
</form>

【讨论】:

我到底应该怎么做?? 是的,这就是问题所在 :) 希望你修复

以上是关于表单操作在 codeigniter 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章

表单验证在 XAmpp 中不起作用

更改另一个选择框值上的选择框在codeigniter中不起作用

表单验证在我的 CI 项目中不起作用(已修复,代码已更新)

数据表库在 CodeIgniter 3 中不起作用

DataTables 函数在 Codeigniter 中不起作用

忘记密码功能在 CodeIgniter 中不起作用