Welcome Guest, Not a member yet? Register   Sign In
How to pass an array as the 2nd parameter to set_rules()
#1

[eluser]cheungj[/eluser]
I know the documentation explains how to pass an array as the first parameter of set_rules(), and it explains how to pass a second parameter is when using a callback, but I'm stuck here.
Here is the code:
Code:
$this->form_validation->set_rules('price_name[]', 'Price Name', 'callback_price_validation['
                .$this->input->post('price_value').']');

Basically, I want to pass two arrays into a custom function, for validation.
The callback is working fine.
The problem is that the <i>price_value</i> array is displaying as a string -- 'Array'.
It's not passing the actual array to the function, it only passes the string.
I'm just not sure how to ensure the array contents are passed to the function.

I'm posting because surely somebody has had to do this before?
Any help is appreciated.
#2

[eluser]jmadsen[/eluser]
cheungi,

Sorry, I'm quoting from memory, but I believe if you:

-- remove the [] from your price_name
-- remove the $this->input->post & the [] from your callback

You will then be able to access this array as


Code:
function price_validation($price_name){
     // $price_name is your array, so iterate over it and do your validation, returning TRUE if it makes it all the way through the array
}
#3

[eluser]cheungj[/eluser]
[quote author="jmadsen" date="1341179659"]cheungi,

Sorry, I'm quoting from memory, but I believe if you:

-- remove the [] from your price_name
-- remove the $this->input->post & the [] from your callback

You will then be able to access this array as


Code:
function price_validation($price_name){
     // $price_name is your array, so iterate over it and do your validation, returning TRUE if it makes it all the way through the array
}
[/quote]

Thanks for the reply.
Sorry, but I'm not exactly sure how to implement your solution.
I know how to pass an array to a function. My problem is that I can't pass an array in as the second parameter to the function.
The function looks like this:
Code:
function price_validation($price_name, $price_value) {
}

I'm also after noticing that the validation rule is run for each element of the array. I have <i>n</i> input fields, meaning that I can have <i>n</i> validations running.




Theme © iAndrew 2016 - Forum software by © MyBB