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

#1
Hello,
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.
Reply

#2
Did you create the below?

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * ----------------------------------------------------------------------------
 * Editor   : PhpStorm 2016.3
 * Date     : 01/5/2017
 * Time     : 6:29 AM
 * Authors  : Raymond L King Sr.
 * ----------------------------------------------------------------------------
 *
 * Class        MY_Form_validation
 *
 * @project     csdmodule
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2017 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ----------------------------------------------------------------------------
 */

/**
 * Class MY_Form_validation
 *
 * SAVE TO: ./application/libraries/MY_Form_validation.php
 *
 * use like this
 * if ($this->form_validation->run($this) == FALSE)
 * {
 *
 * }
 * else
 * {
 *
 * }
 */
class MY_Form_validation extends CI_Form_validation
{

    
/**
     * Class properties - public, private, protected and static.
     * ------------------------------------------------------------------------
     */


    // ------------------------------------------------------------------------

    /**
     * run ()
     * ---------------------------------------------------------------------------
     *
     * @param   string $module
     * @param   string $group
     * @return  bool
     */
    
public function run($module ''$group '')
    {
        (
is_object($module)) AND $this->CI = &$module;

        return 
parent::run($group);
    }

    
// ------------------------------------------------------------------------

  // End of MY_Form_validation Class.

/**
 * ----------------------------------------------------------------------------
 * Filename: MY_Form_validation.php
 * Location: ./application/libraries/MY_Form_validation.php
 * ----------------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
Hi,
Yes, I have the 'MY_Form_validation' file created in the application's library folder.

PHP Code:
function run$module ''$group '' )
 
 {
 
   is_object$module ) ) AND $this->CI = &$module;
 
   return parent::run $group );
 
 

I also just noticed your function was explicitly declared 'public'.  I just tried that also, and same outcome.
I do call the form validation the same way:
PHP Code:
if ( $this->form_validation->run$this ) == FALSE 

I doubt it wold be an issue, but I do set the CI 'system' folder outside the web server's htdocs folder.  This would not explain one form validation working correctly with multiple input validations and another with just one form input validation.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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