• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Re-populating forms

I have set up a form using the form-helper syntax and the input looks like this:

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:

echo form_input('username','','id="username",value="set_value('username')"');

but it doesn't work, and neither does this:

echo form_input('username','set_value('username')','id="username"');

Can anyone put me wise?

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-gui...latingform

echo form_input('username','set_value('username')','id="username"');

Should be:

echo form_input("username","set_value('username')","id='username'");


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:

$un = set_value('username');

and put $un in the expression. That seemed to work.

Many many thanks for your help

Did you try this?
echo form_input('username',set_value('username'),'id="username"');
If you want to use the output of a function as an input param in another function you cannot wrap it in quotes, because the quotes denote a string of text.

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.

[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')

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!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.