![]() |
form_validation - get field value in callback function - 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: form_validation - get field value in callback function (/showthread.php?tid=25621) |
form_validation - get field value in callback function - El Forum - 12-18-2009 [eluser]Dirk Einecke[/eluser] Hi, how can I get the value of a specific form field in a callback function of a form_validation rule? I asked because the content of the callback function depends on two form fields. greetings Dirk Einecke form_validation - get field value in callback function - El Forum - 12-18-2009 [eluser]saidai jagan[/eluser] check <a href="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks">here</a> form_validation - get field value in callback function - El Forum - 12-18-2009 [eluser]Colin Williams[/eluser] Code: $this->input->post('other_field'); form_validation - get field value in callback function - El Forum - 12-18-2009 [eluser]Dirk Einecke[/eluser] Hi, okay ... some code to clarify... Code: $this->form_validation->set_rules('username', 'User name', 'trim|required|min_length[5]|max_length[255]|callback_username_check'); With $this->input->post('first_name'); I get only the original value of the "first_name" field and $str only contains the value of the "username" field. Dirk form_validation - get field value in callback function - El Forum - 12-18-2009 [eluser]Colin Williams[/eluser] All form_validation prepping is applied directly to the $_POST array. But, given the order in which your fields are defined, your username callback will fire before the validation class has a chance to process the first_name field. In other words, you can't access the result of a process that has yet to happen. form_validation - get field value in callback function - El Forum - 12-18-2009 [eluser]Dirk Einecke[/eluser] Hi, [quote author="Colin Williams" date="1261166172"]All form_validation prepping is applied directly to the $_POST array.[/quote] Thank's for this hint. That helps me. [quote author="Colin Williams" date="1261166172"]But, given the order in which your fields are defined, your username callback will fire before the validation class has a chance to process the first_name field.[/quote] Well .... okay. I will play a little bit with the order of the rules. I think I can solve my problem this way. Tank's for your help! Dirk |