【发布时间】: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') ?>
-
为什么?
<?=@DanishAli 有什么问题 -
嗨 pradeep,print_r 给出了相同的结果。在 index.php 的顶部添加 die(var_dump($_POST)) 时,我可以看到我的 POST 数据。但不在控制器中
标签: php forms codeigniter post codeigniter-3