Form validation and default values |
[eluser]yehiasalam[/eluser]
Hi, I have a form that require server side validation, and in addition i need to prefill it from existing values in the database, all the examples i saw from the community were 2 separate functions, one for displaying the initial edit page, and another one for the form submition itself (something like this with update and updatePerson), but what i'm actually doing is using the same function for both the prefilling and the validation taking the advantage of the set_value function and wanted to check if this is good practice, here is the code: Code: function edit(){ and for the view Code: <label for="profile_name_first">First Name: </label> Thanks In Advance Regards. Yehia A.Salam
[eluser]jedd[/eluser]
Yes, as I understand it, this is all good practice. Your code: Code: <input type="radio" name="profile_gender" value="1" <?php echo set_radio('profile_gender', '1', $profile_gender_male); ?>/> Male One thing you might want to do is use the form helper functions. An excerpt from one of my views: Code: $first_name_spec = array ( "name" => "first_name",
[eluser]octavianmh[/eluser]
Could I request an example like the above be brought into the form validation and helper documentation? This just saved me a ton of time, I knew it was possible, but wasn't sure the best-practice way of accomplishing it, and it's not spelled out well in the docs! Thanks. -matt |
Welcome Guest, Not a member yet? Register Sign In |