CodeIgniter Forums
Using form validation on edit form and having form re-population? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Using form validation on edit form and having form re-population? (/thread-30005.html)



Using form validation on edit form and having form re-population? - El Forum - 04-29-2010

[eluser]warpkid[/eluser]
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?

Thanks


Using form validation on edit form and having form re-population? - El Forum - 04-29-2010

[eluser]billmce[/eluser]
You want to check out the form_validation page.
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

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


Using form validation on edit form and having form re-population? - El Forum - 04-29-2010

[eluser]warpkid[/eluser]
Hi,

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.

Thanks


Using form validation on edit form and having form re-population? - El Forum - 04-29-2010

[eluser]mattpointblank[/eluser]
Try this:

Code:
<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.