CodeIgniter Forums
Enhancements/Corrections in form_helper and form_validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Enhancements/Corrections in form_helper and form_validation (/showthread.php?tid=22310)



Enhancements/Corrections in form_helper and form_validation - El Forum - 09-04-2009

[eluser]j2more[/eluser]
Hi there.

I am using CI 1.7.1:

I suggest to enhance/correct the following in form_helper/form_validator:

Currently these classes are not designed to prepopulate fields in forms, but just submitted forms that return some errors typically. With only some small changes this can be achieved though.
Goals:
- I would like to prepopulate my unsubmitted form with values
- I do not want to load form validator for this
- I would like this to be working with several forms in a page

Solution:
change the following files as below:

It works for me. Discussion welcome, Ben

set_select:
form_validation line 748:
old: if ($default === TRUE AND count($this->_field_data) === 0)
new: if ($default === TRUE )

form helper: line 647:
old: if (count($_POST) === 0 )
new: if (count($_POST) === 0 && $default)

set_radio:
form_helper line 755:
old:if (count($_POST) === 0 )
new: if (count($_POST) === 0 && $default )

form_Validation: line 792;
old:if ($default === TRUE AND count($this->_field_data) === 0)
new:if ($default === TRUE )

set_checkbox:
form_helper line 702:
old:if (count($_POST) === 0 )
new:if (count($_POST) === 0 && $default)

form_validation line: 832:
old:if ($default === TRUE AND count($this->_field_data) === 0)
new:if ($default === TRUE )

set_value is already correct..