php - Why isn't my CodeIgniter Form Validation working? -
I am trying to set up verification on a simple contact form which is created using the form assistant. There is no recognition at all what is wrong?
In the code below, the "good" keyword always shows, whether the form is entered in the form, and the saved values set by the set_value are never shown.
> Controller // Contact function contact () {$ data ['pageTitle'] = "contact"; $ Data ['bodyId'] = "contact"; $ This- & gt; Load-> Library ('form_validation'); $ Config_rules = Array ('email' = & gt; 'required', 'message' = & gt; 'required'); $ This- & gt; Form_validation- & gt; Set_rules ($ config_rules); If ($ this-> form_validation-> run () == FALSE) {echo "bad"; $ Data ['include'] = "v_contact"; $ This- & gt; Load-> View ('v_template', $ data); } And {echo "good"; $ Data ['include'] = "v_contact"; $ This- & gt; Load-> View ('v_template', $ data); }}
See
Valid_arrow (); Echo form_open ('Event / Contact'); // name echo form_label ('name', 'name'); $ Data = array ('name' = & gt; 'name', 'id' = & gt; 'name', 'maxlength' => '64 ',' size '=>,' 40 ',' Value '= & gt; set_value (' name ')); Echo form_input ($ data) "\ N
" // email address echo form_label ('email address', 'email'); '$', 'Size' = & gt; 'email', 'id' => 'email', 'maxlength' = & gt; '64 ',' size '=> 40, Value '= & gt; Set_value (' email ')); Echo form_input ($ data) "\ N
" // Message echo form_label ('message', 'message'); $ 'Data' = array = 'name' = '(' name '= & gt;' message ',' id '=>' message ',' rows' = & gt; '8', 'cols' => Value '= & gt; Set_value (' message ')); Echo form_textarea ($ data) "\ n
"; Echo form_submit ('mysubmit', 'send message'); Echo form_close ();
It seems that you are not setting verification rules according to the new rule < Code> Form_validation libraries (there is a new syntax in the user guide). It seems syntax for the old validation
library.
Try your $ config_rules
array instead and see that your validity runs properly:
$ config_rules = array (array ('Field' = & gt; 'email', 'rule' = & gt; 'required'), array ('field' = & gt; 'message', 'rule' = & gt; 'expected')); $ This- & gt; Form_validation- & gt; Set_rules ($ config_rules);
Comments
Post a Comment