我通过$idURL 传递一个变量,并以表单形式加载数据,但是当我要验证表单时,$id无法识别该值.
function myfunction() {
$id = $this->uri->segment(4);
echo $id; //yes, print the value
$data_user = $this->admin_model->query_data_user($id);
$direccion = $data_user[0]->address;
$phone = $data_user[0]->phone;
$this->data['address'] = array(
'name' => 'address',
'id' => 'address',
'value' => $address,
'class' => 'input',
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'value' => $phone,
'class' => 'input',
);
echo $id; //yes, print the value
$this->form_validation->set_rules('address', 'Address', 'xss_clean|max_length[100]');
$this->form_validation->set_rules('phone', 'Phone', 'required|xss_clean|max_length[20]|is_natural_no_zero');
if ($this->form_validation->run() == true) {
echo $id; //here NOT PRINT $id
$data = array(
'address' => $this->input->post('address'),
'phone' => $this->input->post('phone'),
);
$id = $this->uri->segment(4);
echo $id; //here not print the value $id
$this->ion_auth->update_user($id, $data);
$this->load->view('includes/template_mensajes', $data);
}
$this->load->view('users/update_user', $this->data);
}
Run Code Online (Sandbox Code Playgroud)
在$id验证我的表单时,无法识别该值,我的错误是什么?
你在哪里提交表格.您确定要在表单的action属性的URI中传递ID.
例如,表单打开标记看起来应该是这样的
<form action="/admin/myfunction/<?= $id ?>">
或使用codeigniter助手
echo form_open('admin/myfunction/' . $id);
| 归档时间: |
|
| 查看次数: |
888 次 |
| 最近记录: |