[eluser]seba22[/eluser]
Hello,
How check is value in form validation is inside allowed values.
For example, user submit a listbox.
It can have some values for example
a
aa
aaa
So i need to make sure that some_listbox have value a or aa or aaa
When i dont use codeigniter i use statement:
Code:
$allowed = array("a", "aa", "aaa");
if (in_array($_POST['someval'], $allowed)) {
// no hacking attempt
$val_for_db=$_POST['someval'];
}
else
{
//hacking attmpt , set default value
$val_for_db='aa';
}
I can clear see, that there is no option like this in manual... so i need to create it by my own.
I extend validation class and add this function:
Code:
function valid_array_element($str, $allowed)
{
if (in_array($str, $allowed)) {
return TRUE;
}
else
{
return FALSE;
}
}
And i don't know how pass array
Code:
$allowed = array("a", "aa", "aaa");
$this->form_validation->set_rules('admin_title', 'Somefield', 'required|valid_array_element[$array]');
But that's of course not working...
Do You have any idea ?
I think we can, serialize and base64 code, and just put this
Code:
valid_array_element['.base64(serialize($array)).']')
But maybe there is other, bether way ?