CodeIgniter Forums
re-populating form after invalid submission - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: re-populating form after invalid submission (/thread-2755.html)



re-populating form after invalid submission - El Forum - 08-22-2007

[eluser]stevefink[/eluser]
I'm trying to re-populate a form after one or more invalid data fields have been submitted. As per the validation user guide, I have the following in my controller:

Code:
$fields['stock']    = 'Stock';
$fields['vin']        = 'VIN';

$this->validation->set_fields($fields);

And the following in my view:

Code:
<label>Stock# <span class="required"> * </span></label>
    &lt;input type="text" name="stock" value="&lt;?=$this-&gt;validation->stock;?&gt;" /> <br>
    
    <label>VIN    <span class="required"> * </span></label>
    &lt;input type="text" name="vin" value="&lt;?=$this-&gt;validation->vin;?&gt;" /> <br>

If any part of the form is not properly submitted, shouldn't those two essentially get repopulated? Instead I get this within my view:

Severity: Notice

Message: Undefined property: CI_Validation::$stock

Filename: console/car_info_view.php

Line Number: 43

and

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Validation::$vin

Filename: console/car_info_view.php

Line Number: 46

Thank you.


re-populating form after invalid submission - El Forum - 08-24-2007

[eluser]chobo[/eluser]
Try setting some validation rules and running the validation after you set the fields. I'm not sure if you can get away with just setting the fields, it might require rules and or you need to also run the validation init method or whatever sets it off. Use the user guide examples as a reference.


re-populating form after invalid submission - El Forum - 08-24-2007

[eluser]Bulk[/eluser]
Yes chobo is correct, you do need to set validation rules for any filed you want repopulated - but importantly the rule can be "empty" if you don't want any real validation performed on the fields.