cabita cabita - 6 months ago 13
PHP Question

Parameter not set after validating form in CodeIgniter

I pass a variable

by URL, and load the data in the form form update but when I am going to validate the form , the value
is not recognized.

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);

The value
is not recognized when it's validated my form, what is my error?


Where are you submitting your form to. Are you sure you are passing the ID in the URI on your form's action attribute.

For example your form open tag should look something like

<form action="/admin/myfunction/<?= $id ?>">

Or using the codeigniter helper

echo form_open('admin/myfunction/' . $id);