Welcome Guest, Not a member yet? Register   Sign In
Callbacks and array ?
#1

[eluser]quasiperfect[/eluser]
i use the latest https://github.com/EllisLab/CodeIgniter
i have in the controller
Code:
$this->load->library('form_validation');  $this->form_validation->set_rules('myarray[]', 'myarray', 'callback__myarray_check');
if ($this->form_validation->run() == FALSE)
{
}
else
{
}
$this->load->view('welcome_message');
the callback function is
Code:
function _myarray_check($str) {
print_r($str);
echo '|';
$this->form_validation->set_message('_myarray_check', 'myarrayerror');
return FALSE;
}

in the view
Code:
<form method="post" action="welcome/">
<input type="checkbox"  name="myarray[]" value="1"> a, <input type="checkbox" name="myarray[]" value="2"> b
<?php echo (form_error('myarray[]'))?(form_error('myarray[]')):('');?>
<input type="submit" value="test">
</form>

on submit i get 1|2|
so the callback is called for each value of the array
is this intended ?
is a bug ?
to me more logical would be to get the array as parameter and to execute the callback once

edit
if nothing is selected the callback is not even called


Messages In This Thread
Callbacks and array ? - by El Forum - 10-03-2011, 05:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB