CodeIgniter Forums
form set_value - 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: form set_value (/showthread.php?tid=58192)



form set_value - El Forum - 05-23-2013

[eluser]jairoh_[/eluser]
i have a form that changes a title's value, but before changing changing it's value, it will have its default value shown. But when the validation of the value is invalid, i want the invalid value will still be there instead of the default value. anyone has an idea? tnx

Code:
<?php echo form_input( 'title', $default_value ); ?>



form set_value - El Forum - 05-23-2013

[eluser]LuckyFella73[/eluser]
hi jairo

have a look at the userguide section "Re-populating the form"

http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html


form set_value - El Forum - 05-23-2013

[eluser]jairoh_[/eluser]
[quote author="LuckyFella73" date="1369305179"]hi jairo

have a look at the userguide section "Re-populating the form"

http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html[/quote]

yeah but if that will happen, how can i show the default value? and the default value was static that means from a database.


form set_value - El Forum - 05-23-2013

[eluser]LuckyFella73[/eluser]
Code:
<?php echo set_value('title', $default_value); ?>

Where $default_value is the value from db.

http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#functionreference

Scroll down a bit and see section "set_value()"


form set_value - El Forum - 05-23-2013

[eluser]jairoh_[/eluser]
[quote author="LuckyFella73" date="1369308640"]
Code:
<?php echo set_value('title', $default_value); ?>

Where $default_value is the value from db.

http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#functionreference

Scroll down a bit and see section "set_value()"[/quote]
yeah, but my default value will be gone if i do that. correct me if i'm wrong.
yes it the invalid value will remain if i'll use set_value but how about my default value in the first load? because if i do set_value, then the default is empty.


form set_value - El Forum - 05-23-2013

[eluser]TheFuzzy0ne[/eluser]
I'm not quite sure what the problem is here. The default value is only required the first time the form is loaded. Each time the form is submitted, the submitted value is used. So:

Code:
<?php echo form_input('title', set_value('title', $default_value)); ?>

...should work exactly as you expect it to.

Please try it, and get back to us if it's not what you expect.


form set_value - El Forum - 05-23-2013

[eluser]jairoh_[/eluser]
[quote author="TheFuzzy0ne" date="1369320978"]I'm not quite sure what the problem is here. The default value is only required the first time the form is loaded. Each time the form is submitted, the submitted value is used. So:

Code:
<?php echo form_input('title', set_value('title', $default_value)); ?>

...should work exactly as you expect it to.

Please try it, and get back to us if it's not what you expect.[/quote]
it solved it. thank you for your post.