Welcome Guest, Not a member yet? Register   Sign In
jquery post & ci form validation
#2

[eluser]Nick Husher[/eluser]
It's maybe slightly bad practice, but you'll need to use a custom validation rule that's described about halfway down the Form Validation page. In the controller method you're using to decode the ajax request, add this validation rule:

Code:
$this->form_validation->set_rules('a','JSON Object','required|callback__handle_object');

And in the same controller, add this function:
Code:
function _handle_object($json_object) {
    $json_object = json_decode($json_object);

    // json_decode returns null or a string if the json given to it is
    // invalid. see:
    // http://us2.php.net/manual/en/function.json-decode.php#86181
    $isValid = ($json_object != null && !is_string($json_object));
        
    // run validation, setting $isValid to false if anything
    // is out of place.
    return $isValid;
}

This code is untested, so it might need some massaging.


Messages In This Thread
jquery post & ci form validation - by El Forum - 01-21-2009, 08:00 AM
jquery post & ci form validation - by El Forum - 01-21-2009, 10:11 AM
jquery post & ci form validation - by El Forum - 01-21-2009, 12:17 PM
jquery post & ci form validation - by El Forum - 01-21-2009, 02:15 PM
jquery post & ci form validation - by El Forum - 01-22-2009, 03:06 AM
jquery post & ci form validation - by El Forum - 01-22-2009, 09:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB