Welcome Guest, Not a member yet? Register   Sign In
Custom validation callbacks trouble
#9

[eluser]WanWizard[/eluser]
Extend the form_validation library:
Code:
class MY_Form_validation extends CI_Form_validation
{
    // storage for the callback object
    var $callback = FALSE;

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

    /**
     * Constructor
     *
     * @return void
     * @access public
     */
    function MY_Form_validation()
    {
        // call the parent constructor
        parent::CI_Form_validation();

        // set the default callback object
        $this->callback = $this->CI;

        // Logs initialization message for debugging
        log_message('debug', 'ExiteCMS Form Validation Class Extension Initialized');
    }
}

Then copy the _execute() method from the CI library to your library, find the bit where the callback method is checked, and replace it by:
Code:
// Call the function that corresponds to the rule
if ($callback === TRUE)
{
    if ( ! method_exists($this->callback, $rule))
    {
        continue;
    }
    // Run the function and grab the result
    $result = $this->callback->$rule($postdata, $param);

After this, you can set the object that contains your callback functions using
Code:
$this->form_validation->callback =& $this; // callback methods can be found in this class
before calling the run() method to have your fields validated.


Messages In This Thread
Custom validation callbacks trouble - by El Forum - 07-15-2010, 06:24 PM
Custom validation callbacks trouble - by El Forum - 07-16-2010, 01:42 AM
Custom validation callbacks trouble - by El Forum - 07-16-2010, 08:47 AM
Custom validation callbacks trouble - by El Forum - 07-16-2010, 12:35 PM
Custom validation callbacks trouble - by El Forum - 07-16-2010, 12:40 PM
Custom validation callbacks trouble - by El Forum - 07-16-2010, 12:43 PM
Custom validation callbacks trouble - by El Forum - 07-16-2010, 12:44 PM
Custom validation callbacks trouble - by El Forum - 07-16-2010, 01:03 PM
Custom validation callbacks trouble - by El Forum - 07-16-2010, 01:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB