• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array passes form validation for string element with the same name -- how to fix?

#3
(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.

PHP Code:
$this->form_validation->set_rules('cms[]''CMS''is_natural_no_zero'); 

See Using Arrays as Field Names

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.)
Reply


Messages In This Thread
RE: Array passes form validation for string element with the same name -- how to fix? - by Stanzi1791 - 09-26-2018, 02:47 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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