Might sound like a dirty hack, but you could spoof a form post by setting $_POST data? Say you receive JSON, you could do something like:
$json = "...."; //json encoded string
$arr = json_decode($json, true);
foreach($arr as $key => $value)
{
$_POST[$key] => $value;
}
// do form validation as if the data was posted from a form.
This is offcourse just a quick fix. You could extend/overwrite parts of the Form_validation library. How I would do it:
- Add a MY_Form_validation.php library, copy paste ALL functions from Form_validation.php that use
$_POST (set_rules(), run(), matches())
- Replace all instances of
$_POST in MY_Form_validation.php with $this->validate_data
- Set
$validate_data to $_POST in the constructor.
- Add a function
set_validate_data() that allows you to overwrite $this->validate_data
You will have to use the $_POST array after the data has been validated, if you want to use the cleaned data. If this is unacceptable, also add a function that cleans $this->validate_data and returns an XSS clean array.