CodeIgniter Forums
form_validation matches[] multidimensional array bug fix :) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: form_validation matches[] multidimensional array bug fix :) (/thread-53228.html)



form_validation matches[] multidimensional array bug fix :) - El Forum - 07-16-2012

[eluser]itsme[/eluser]
I found that the current matches method in form_validation library does not support fields with multidimensional
array as a name so i edited the method to support it, i hope it will help you in the future Smile

The new method is :-

Code:
public function matches($str, $field)
{
  if(strpos($field,"]"))
  {
   list($arr_name,$field_name)=explode("[",$field);
  
   $field_name=substr($field_name,0,-1);
  
   if ( ! isset($_POST[$arr_name][$field_name]))
   {
    return FALSE;
   }
  
   $field = $_POST[$arr_name][$field_name];
  
  
  }
  else {
   if ( ! isset($_POST[$field]))
   {
    return FALSE;
   }

   $field = $_POST[$field];
  }
  
  
  return ($str !== $field) ? FALSE : TRUE;
}




form_validation matches[] multidimensional array bug fix :) - El Forum - 07-16-2012

[eluser]Phil Sturgeon[/eluser]
When you find a bug can you please report it on GitHub, or send a pull request?

Also, please use code tags when you post code to the forums, it's tough to read otherwise.


form_validation matches[] multidimensional array bug fix :) - El Forum - 07-16-2012

[eluser]itsme[/eluser]
thanks Phil Sturgeon , i edited my post and write the issue on GitHub bug tracker