[eluser]mattpointblank[/eluser]
Hi all.
I'm doing some basic CRUD forms and for my edit page, I want to display the fields stored in the database upon page load. When the user submits the form, I want the validation function to run, and then show them the form again, this time with their (potentially different) $_POST values instead.
This means I can't use the set_value() function as my form field values, otherwise on the first page load, the values from my database aren't present. Similarly, I can't just assign my database fields as the form values either, because then when the form's posted, it will overwrite the $_POST data with the stored data. Confusing!
I've been getting around this using this code at the start of each form view:
Code:
if(!$url = set_value('URL')) { $url = $row['url']; }
Then in the form, I just do:
Code:
<input type="text" name="url" value="<?php echo $url; ?>" />
This works, but I can't help but feel it's a bit messy. Is there a better method for this sort of thing?
Thanks
Matt
[/code]