[SOLVED] Fill fields with some value if I'm editing but also re-populating the form on submit |
[eluser]ReyPM[/eluser]
Hi every, I'm building a CRUD for a table (not using any external tool) but I'm confused here while editing a record. As said here at docs Form Validation for re-populating the form I must use the set_value() function but what if I'm editing a record where value is populated from returned data by a previous query? How to handle the re-populating in this case? Any help or advice?
[eluser]CroNiX[/eluser]
Code: set_value($field, $default); $default will be used when the page first loads. $field value will be used if the form was submitted. It's (2nd paramter of set_value()) not explained in the Form Validation section of the User Guide, but it is in the Form Helper section.
[eluser]ReyPM[/eluser]
[quote author="CroNiX" date="1352150787"] Code: set_value($field, $default); $default will be used when the page first loads. $field value will be used if the form was submitted.[/quote] So if I'm right $default should be the value come from DB and $field should be the value for the re-populating? Also could you please write a small example in how logic should be from the controller? I'm lost here by the way thanks
[eluser]CroNiX[/eluser]
Yes. controller Code: //get user data value for field1 //view Code: <input type="text" name="field1" value="<?php echo set_value('field1', $user_data['field1']; ?>" /> When the page/form first loads, it will have "one" for the value in the "field1" form field. Once submitted, it will be whatever value was in the "field1" field.
[eluser]ReyPM[/eluser]
Ok so there is not need for this code: Code: value="<?php echo!isset($article) ? set_value('number_pub', $article->NUMBER) : set_value('number_pub'); ?>"
[eluser]ReyPM[/eluser]
Ahh one last question, what about SELECT, CHECKBOX and OPTION BUTTON? How to deal with those?
[eluser]CroNiX[/eluser]
Those have their own functions since they differ. See the bottom of the Form Helper section of the user guide.
[eluser]ReyPM[/eluser]
Ok, I'll check also see this case (maybe I'm wrong) Code: $revista = array(); When $revista is empty I get this error: Quote:A PHP Error was encounteredWhere line Number 37 is set_value .... What I'm doing wrong here? |
Welcome Guest, Not a member yet? Register Sign In |