Array passes form validation for string element with the same name -- how to fix? |
(09-25-2018, 09:04 PM)dave friend Wrote: If the field name is an array - i.e. cms[] - then you must use the exact same for your Validation Rule field name. e.g. Thank you for your reply. I understand that if I want to use an array, I have to alter the validation rules. But that is not what my question is about: I was trying to simulate the case where someone sends a forged post request to my controller, in which case it shouldn't validate. After some further research I really do think there's a bug in CodeIgniter's the form validation code. I fixed it by creating a file at application\libraries\MY_Form_validation.php, copying the _execute function, and replacing this // If we get an array field, but it's not expected - then it is most likely // somebody messing with the form on the client side, so we'll just consider // it an empty field $postdata = is_array($this->_field_data[$row['field']]['postdata']) ? NULL : $this->_field_data[$row['field']]['postdata']; with this // If we get an array field, but it's not expected - then it is most likely // somebody messing with the form on the client side, so we'll just consider // it an empty field $postdata = is_array($this->_field_data[$row['field']]['postdata']) ? "" : $this->_field_data[$row['field']]['postdata']; $this->_field_data[$row['field']]['postdata'] = $postdata; (Using NULL won't work here, because NULL values are not re-assigned to the $_POST array by the _reset_post_array function.) |
Messages In This Thread |
Array passes form validation for string element with the same name -- how to fix? - by Stanzi1791 - 09-25-2018, 01:55 PM
RE: Array passes form validation for string element with the same name -- how to fix? - by dave friend - 09-25-2018, 09:04 PM
RE: Array passes form validation for string element with the same name -- how to fix? - by Stanzi1791 - 09-26-2018, 02:47 AM
|