CodeIgniter Forums

Full Version: Using form validation on edit form and having form re-population?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi There,

I have a simple form in codeigniter that I wish to use for the editing or records. I am at the stage where my form is displayed and the values entered into the corresponding input boxes.

This is done by simply setting the values of said boxes to whatever they need to be in the view:

<input type="text" value="<?php echo $article['short_desc'];?>" name="short_desc" />

But, if I wish to use form_validation in codeigniter then I have to add thos code to my mark-up:

<input value="<?php echo set_value('short_desc')?>" type="text" name="short_desc" />

So not the value can be set with the set_value function should it need to be repopulated on error from the post data.

Is there a way to combine the two so that my edit form can show the values to be edited but also re-populate?


El Forum

You want to check out the form_validation page.

About 1/2 down that page, where it discusses 'callbacks' is an example of what you're looking to accomplish.

El Forum


I've checked out the sections on callbacks and can't see how they can be used to solve my issue. Unless I'm missing a trick.

I've reworded my question as I think it was a little confusing.


El Forum

Try this:

<input type="text" name="email" value="<?php echo set_value('email', $user['email']); ?>" />

First time you load the form it'll show the $user['email'] value from your database. If you change this value then submit the form (but make a validation error somewhere) it'll remember the updated value you changed.