[eluser]Frank Rocco[/eluser]
Hello, the code below produces a field is required message when the form is first displayed.
I cannot seem to fix this.
Does the code look ok?
Code:
//View
$Item_description = array(
'name' => 'Item_description',
'id' => 'Item_description',
'value' => $results->Item_description,
'maxlength' => '60',
'size' => '70',
'style' => 'width:70%',
);
<tr>
<td><?php echo form_label('Item Description ','Item_description', $attributes); ?></td>
<td><?php echo form_input($Item_description); ?></td>
<td><?php echo form_error('Item_description'); ?></td>
</tr>
// Controller
function edit($Item)
{
$data['results'] = $this->product_model->getRecords(array('Item' => $Item));
if (!$data['results'])
{
$this->session->set_flashdata('flashError', 'Record not found, please contact your administrator.');
redirect('product');
}
// Fill Category Dropdown Box
$data["cat"] = $this->category_model->fillCombo();
// Validate form
$this->form_validation->set_error_delimiters('<span style="color: red" class="error">', '</span>');
$this->form_validation->set_rules('Item_description', 'Item Description','trim|required');
$this->form_validation->set_rules('Extended_description', 'Extended Description','trim|required|min_length[4]');
$this->form_validation->set_rules('Size', 'Size','trim|required');
$this->form_validation->set_rules('Sizenum', 'Sizenum','trim|required');
$this->form_validation->set_rules('List_price', 'List Price','trim|required');
$this->form_validation->set_rules('Price1', 'Price1','trim|required');
$this->form_validation->set_rules('Price2', 'Price2','trim|required');
$this->form_validation->set_rules('Price3', 'Price3','trim|required');
$this->form_validation->set_rules('On_hand_qty', 'On Hand Qty','trim');
if ($this->form_validation->run())
{
//$_POST['Item'] = $Id;
//if (empty($_POST['userPassword'])) unset($_POST['userPassword']);
if ($this->product_model->updateRecord($_POST))
{
$this->session->set_flashdata('flashConfirm', 'Record has been successfully updated.');
redirect('product');
}
else {
$this->session->set_flashdata('flashError', 'Record not updated! No Changes were made.');
redirect('product');
}
}
$this->template->write('menu', anchor($this->session->userdata('returnPage'),'Cancel Request'));
$this->template->write('title','Edit Record');
$this->template->write_view('content','product/edit_form', $data, FALSE);
$this->template->render();
}
Thank you...