我在提交表单后获取发布数据时遇到问题。我尝试做的是,当用户单击提交按钮时,存储在隐藏字段中的输入值将被分配给另一个控制器类中的变量。但是,当我尝试打印表单值时,它总是给我NULL
这是我的代码:
控制器
public function updateOrder(){
$this->form_validation->set_rules('delivery_status_id', 'Delivery Status', 'xss_clean');
$this->form_validation->set_rules('remarks', 'Remarks', 'xss_clean');
$this->form_validation->set_rules('total_amt', 'Total Amount', 'xss_clean');
$data = array('remarks' => $this->input->post('remarks'),
'delivery_status_id' => $this->input->post('delivery_status_id'),
'total_amt' => $this->input->post('total_amt'));
if ($data['delivery_status_id'] == $getDeliveryStatusIdDelivered->row('id'))
{
$this->db->select('*');
$this->db->from('user_has_penalty');
$this->db->where("user_id =" . $this->session->userdata['id']);
$query = $this->db->get();
foreach ($query->result() as $row)
{
$this->db->delete('user_has_penalty', array('user_id' => $this->session->userdata['id']));
$this->db->delete('penalty', array('id' => $row->penalty_id));
}
}else if($data['delivery_status_id'] == $getDeliveryStatusIdCancelled->row('id'))
{
$penalty_amt = $data['total_amt'] / 2;
$data = array('amount' => $penalty_amt);
$this->penalty->insert($data);
$penalty_id = $this->db->insert_id();
//var_dump($penalty_id);
}
var_dump($this->input->post); // Outputs NULL
}
查看
...
<?php
$name_c = 'Cancelled';
$query = $this->DeliveryStatus->getDeliveryStatusByName($name_c);
echo form_open('Order_Controller/updateOrder');
?>
<input type="hidden" name="delivery_status_id" value="<?php echo $query->row('id'); ?>"/>
<button type="submit" class="btn btn-danger">YES</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<?php echo form_close(); ?>
代码有问题吗?任何帮助将不胜感激
答案 0 :(得分:1)
在您的表单标记中,如果您未指定方法,则它将是get
方法。
<form action="Order_Controller/updateOrder" method="post">
...
</form>
答案 1 :(得分:0)
您缺少表单标记中的method
。
form_open('order_Controller/updateOrder', array('method'=>'post'));
注意: