[eluser]mortenfrisi[/eluser]
I'm building a site where a user can add an item, which consist of title (item_title), description (item_desc) and size (item_size).
The user should be able to update this information, but I have a hard time figuring out what to do when the user update an item that doesn't go through the validation.
I have made the script below, but it's there an easier way?
Code:
// check if there is an validation error (it will output an set_value
if ( set_value('title')
OR set_value('description')
OR set_value('size')
){
$value_title = set_value('title');
$value_desc = set_value('description');
$value_size = set_value('size');
}
else {
// there is no validation error, so we show what we got from the database
$value_title = $db_result[0]->title;
$value_description = $db_result[0]->description;
$value_size = $db_result[0]->size;
}
// creating the array for the form
$title = array(
'name' => 'title',
'value' => $value_title,
);
$description = array(
'name' => 'description',
'value' => $value_desc,
);
$size = array(
'name' => 'size',
'value' => $value_size,
);
<!-- show the form -->
<p><?php echo form_label('Description', $description['id']); ?></p>
<p><?php echo form_textarea( $description); ?></p>
<div class="error"><?php echo form_error( $description['name']); ?><?php echo isset($errors[$description['name']])?$errors[$description['name']]:''; ?></div>
<!-- etc -->
Maybe there is a better way?