CodeIgniter Forums

Full Version: form_validation matches[] multidimensional array bug fix :)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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;
}

El Forum

[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.

El Forum

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