Welcome Guest, Not a member yet? Register   Sign In
Custom validation rule + array
#1

[eluser]sqwk[/eluser]
When I am passing aan array (from a multi select) to a custom validation rule via callback_, the rule doesn't receive the array, but rather all the nodes separated by nothing.

Running a var_dump inside the validation rule produces something like this:

Code:
string(1) "1" string(1) "3"

How can I pass the array to the validation rule? (To count nodes etc.)
#2

[eluser]sqwk[/eluser]
Is this a bug?
#3

[eluser]Mark Croxton[/eluser]
Does your <select> element have square brackets after the name [] ?
#4

[eluser]sqwk[/eluser]
yes…

EDIT:
The other thing that I tested was applying a generic rule like this: (In this case the array is an additional variable)

Code:
… 'required|callback__in_array('.array("val","val2","val2").')' …

function _in_array($val, $array) {
   if (in_array($val, $array)
      return TRUE;
   else
      return FALSE;
}
#5

[eluser]Mark Croxton[/eluser]
Ok, to answer your original question: why not look at the values in the $_POST global: $_POST['my_element[]']?

Or better, use CI's input class: $this->input->post('my_element[]');

EDIT: now you've edited your last post I see what you're trying to do. I believe CI parses those rules with a regular expression so using an array there won't fly. Why not pass as a string with a delimiter and explode() back into an array?




Theme © iAndrew 2016 - Forum software by © MyBB