• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form Validation of array variables and form_error() and set_value()

#1
[eluser]Eric Cope[/eluser]
This is more of information post, so others can benefit from my toils...

Ok, I was able to dig down to the root cause of this error.
If I submit a POST array like this:
Code:
<input name="var1[]" value="something" />
<input name="var1[]" value="" />

and apply the following form validation rules:
Code:
trim|max_length[255]|alpha_numeric

The second value in the array will fail validation even though its not required as defined in the rule list.

Additionally, form_error() only stores a single error message, which prevents the user from properly identifying which index in the array is erroneous.

Finally, set_value() returns a single value, requiring me to use a while loop to extract all of the values. The forums indicate they may return an array. Can anyone confirm this is for CI2.x?

#2
[eluser]Eric Cope[/eluser]
I should mention that I work around this by adding a new alpha_numeric test which also allows 0-length strings.

#3
[eluser]mariek[/eluser]
Hi, same problem here :
http://ellislab.com/forums/viewthread/184553/
(no solution yet unfortunatly)

#4
[eluser]Eric Cope[/eluser]
I have some ideas on how to fix it. Maybe I'll submit a patch to Phil.

#5
[eluser]louisl[/eluser]
Wouldn't you use a callback in that situation seeing as it's an array then process validation in the callback function and set custom errors. Maybe not the easiest method but you're essentially asking 'is this array alpha_numeric' as opposed to 'is everything in this array alpha_numeric' if I'm understanding it right?

#6
[eluser]Eric Cope[/eluser]
That may be one way. I'd prefer a more automatic method.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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