• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form Validation Callback Executing First

I have been using both CI v2.x.x and v3.x.x with wiredesignz HMVC plug-in with very few issues that could not have its own work around.

There is one strange one, which I have yet to figure out, but work around it, is with the Form Validation and callbacks.

On a localhost development set up, using XAMPP, I have a sign up page which validates: first name; last name; email address; confirm email address; password; confirm password; a 'human interaction'; terms and conditions checkbox.

The form validation is set up to use HMVC and works as expected when validating the sign up form.  The rules for the validation - in a model though, not a controller.

PHP Code:
$this->form_validation->set_rules'first_name''First name''trim|required|min_length[2]|max_length[50]' );
$this->form_validation->set_rules'last_name''Last name''trim|required|min_length[2]|max_length[50]' );
$this->form_validation->set_rules'email_address''Email address''trim|required|valid_email|callback__unique_email_address_check' );
$this->form_validation->set_rules'confirm_email''Confirm email''trim|required|valid_email|matches[email_address]' );
$this->form_validation->set_rules'password''Password''trim|required|min_length[10]|matches[confirm_password]' );
$this->form_validation->set_rules'confirm_password''Confirm password''trim|required|min_length[10]' );
$this->form_validation->set_rules'human_interaction_status''Human Sign Up Check''callback__check_human_interaction_status' );
$this->form_validation->set_rules'terms_and_conditions''Terms and Conditions''callback__check_terms_and_conditions_checkbox' ); 

I also have a page for people to resend an account verification email.  This page has only one form field to validate, that is the email address field.

The rule for the validation is:
PHP Code:
$this->form_validation->set_rules'email_address''Email address''trim|required|valid_email|callback__email_address_check' ); 

The validation for this page runs only the callback function, none of the other validation rules are checked.  If I remove the callback and submit empty field, 'required' rule is returned as expected, as is 'valid_email' if email address not valid.

Both the sign up page and verification email page have the forms posted the same way via Ajax.

I have a work around in the meantime which works, that is, validate twice.  Not ideal but works.  First validation set of rules omit the callback.  Once that has passed, the callback only is checked, if that passes validation, script continues.

Any thoughts anyone?  This has been the case for both CI v2.x.x and v3.x.x and the HMVC plug-in.

Messages In This Thread
Form Validation Callback Executing First - by Mr Lister - 02-04-2017, 12:32 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.