【问题标题】:CodeIgniter POST call Output Status : 303 See OtherCodeIgniter POST 调用输出状态:303 查看其他
【发布时间】:2018-03-28 08:48:06
【问题描述】:

过去 3 天我一直在尝试在 Codeigniter 中进行 POST 调用,但无法获取 POST 数据。

我最初有它的表格格式,但在探索中,我发现在 CodeIgniter 中从表格中获取输入字段会带来很多错误。所以今天我用普通的输入元素尝试了它。我仍然无法检索 POST 数据。

页面 URL 形成: http://localhost/myproject/set-schedule

表格:

<?= form_open('set-schedule') ?>
              <div class="form-group">
                  <label>Select Date: </label>
                  <?php
                        $formData = "";
                        if(isset($_GET['date'])) {
                          $formData = $this->schedule_model->get_data($_GET['date']);
                          echo "<input type=\"text\" class=\"date-picker\" id=\"add_date\" value=" . $_GET['date'] ."></input>";
                        } else {
                          echo "<input type=\"text\" class=\"date-picker\" id=\"add_date\"></input>";
                        }
                  ?>
              </div>

                <div class="div-table">
                   <div class="div-table-row">
                      <div class="div-table-col heading" align="center">DATE</div>
                      <div  class="div-table-col heading">Head1</div>
                      <div  class="div-table-col heading">Head2</div>
                      <div  class="div-table-col heading">Head3</div>
                      <div  class="div-table-col heading">Head4</div>
                   </div>

                  <?php for ($row = 1; $row <= 7; $row ++) { ?>
                        <div class="div-table-row" id="form_data_custom">
                          <div class="div-table-col" align="center">
                            <?php echo "<input type='text' class='form-group' name='date_" . $row . "' placeholder='Enter DATE' readonly></input>"; ?>
                          </div>
                          <div class="div-table-col" align="center">
                            <?php echo "<input type='text' class='form-group' name='a_" . $row . "' placeholder='Enter Entry A'></input>"; ?>
                          </div>
                          <div class="div-table-col" align="center">
                            <?php echo "<input type='text' class='form-group' name='b_" . $row . "' placeholder='Enter Entry B'></input>"; ?>
                          </div>
                          <div class="div-table-col" align="center">
                            <?php echo "<input type='text'  class='form-group' name='c_" . $row . "' placeholder='Enter Entry C'></input>"; ?>
                          </div>
                          <div class="div-table-col" align="center">
                            <?php echo "<input type='text' class='form-group' name='d_" . $row . "' placeholder='Enter Entry D'></input>"; ?>
                          </div>
                        </div>
                  <?php } ?>

              </div>
              <div class="form-group text-right">
                <input type="submit" class="form-group btn btn-primary btn-sm" value="Submit"> Add/Update
                </input>
              </div>

            </form>

路线:

$route['set-schedule'] = 'schedule/set';

控制器(schedule.php):

    public function set()
    {
        var_dump('HERE');

        // create the data object
        $data = new stdClass();

        // load form helper and validation library
        $this->load->helper('form');
        $this->load->library('form_validation');


        $form_data = $this->input->post();
        echo json_encode($_POST);
        echo json_encode("----");
        echo json_encode($form_data);

        ........
}

将所有 POST 数据设为 NULL

请指导我可能会出错的地方。谢谢

【问题讨论】:

  • 我还可以在“表单数据”下看到在 chrome 调试器中提交的用于 post 调用的数据
  • 你试过这样 print_r($this->input->post());
  • 使用这个 INSTEAD OF = form_open('set-schedule') ?>
  • 为什么? &lt;?=@DanishAli 有什么问题
  • 嗨 pradeep,print_r 给出了相同的结果。在 index.php 的顶部添加 die(var_dump($_POST)) 时,我可以看到我的 POST 数据。但不在控制器中

标签: php forms codeigniter post codeigniter-3


【解决方案1】:

你试过了吗:

使用这行代码

     public function set()
     {
        var_dump($this->input->post());
        /*--OR---*/
        var_dump($_REQUEST);
         /*--OR---*/
        print_r($this->input->post());
        die;
     }

【讨论】:

  • 变空 : string(8) "HERE" array(0) { } array(0) { } Array ( ) []
  • 打印任何东西并在你的控制器中死掉以检查 url 是否正常工作
  • 这很奇怪。当我添加 die 时,我现在可以看到数据了!这是为什么。这是否意味着我正在获取数据但无法打印它,
  • 你必须使用 die 来阻止页面的进一步处理
  • @zeetit 在所有输入字段中添加名称属性以获取您的表单数据
猜你喜欢
  • 2018-12-27
  • 1970-01-01
  • 1970-01-01
  • 2018-10-12
  • 2012-09-13
  • 2014-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多