Re-populating forms - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Re-populating forms (/showthread.php?tid=43356) |
Re-populating forms - El Forum - 07-08-2011 [eluser]Perkin5[/eluser] I have set up a form using the form-helper syntax and the input looks like this: Code: echo form_input('username','','id="username"'); and I want to repopulate it with POST array data. I'm assuming you have to use set_value(). The user guide shows you how to do it when you're not using the form helper but I can't find how to do it with the form helper. I've tried this: Code: echo form_input('username','','id="username",value="set_value('username')"'); but it doesn't work, and neither does this: Code: echo form_input('username','set_value('username')','id="username"'); Can anyone put me wise? Re-populating forms - El Forum - 07-08-2011 [eluser]smilie[/eluser] It is important that you are using form_validation for this, as that class is managing form re-populating. See: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#repopulatingform Btw, Code: echo form_input('username','set_value('username')','id="username"'); Should be: Code: echo form_input("username","set_value('username')","id='username'"); Cheers, Smilie Re-populating forms - El Forum - 07-08-2011 [eluser]Perkin5[/eluser] Many thanks for your response. I understand your point about the quotes and used your code snippet but all that happened was that the words set_value('username') appeared in the input box rather than the POST array value. What I did in the end was to say: Code: $un = set_value('username'); and put $un in the expression. That seemed to work. Many many thanks for your help Re-populating forms - El Forum - 07-08-2011 [eluser]fesweb[/eluser] Did you try this? Code: echo form_input('username',set_value('username'),'id="username"'); Re-populating forms - El Forum - 07-08-2011 [eluser]Perkin5[/eluser] I hadn't tried it but I have now - works great! Thanks again. Why is that not in the user guide I wonder? Maybe it is and I'm too blind to see but I've had a good search. Re-populating forms - El Forum - 07-08-2011 [eluser]fesweb[/eluser] [quote author="Perkin5" date="1310181850"] Why is that not in the user guide I wonder? Maybe it is and I'm too blind to see but I've had a good search.[/quote] Yes, the documentation could do a better job of integrating the form helper and form validation examples. But, not putting a function call in quotes is just basic PHP... Friday Freebie reminder: set_value() has an optional second parameter to set a default value: set_value('favorite_day_of_the_work_week', 'Friday') Re-populating forms - El Forum - 07-08-2011 [eluser]Perkin5[/eluser] Oh Boy - Santa Claus came early! What a great tip! I admit I'm not so hot on PHP which is why I prefer to use Codeigniter - I know what you're going to say - I should have had a good knowledge of PHP before I started. But with the excellent user guide and the help of fantastic guys like you, actually I'm doing OK. May the force be with you! |