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

[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:
<input name="var1[]" value="something" />
<input name="var1[]" value="" />

and apply the following form validation rules:

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?

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

Hi, same problem here :
(no solution yet unfortunatly)

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

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?

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