Welcome Guest, Not a member yet? Register   Sign In
Form validation, form array, loop, too many sql calls
#1

[eluser]CrustyDOD[/eluser]
Hey!

Imagine a form field, checkboxes with name="something[]"

Form validation
Code:
$this->form_validation->set_rules('something[]', 'something', 'callback__checkValues');
_checkValues function queries table to check if selected item really exist.

Now let's say you have a form with around N checkboxes per page. User selects ALL checkboxes,
and submits the form.

Result = N queries because form_validation loops over something[] array and calls the rules each time which is fine until
you have a situation like above with sql involved..

How would you guys solve this to make 1 query like:
Code:
SELECT ... IN ('something[]')

The only way i can think of is to call a function like:
Code:
if ($this->form_validation->run() == TRUE)
{
    if (someFunction($this->input->post('something[]')) == FALSE)
    {
        // set error message and save it to session
        // refresh page
    }

    // form was successfully submitted code here..
}

Is there a better way?
#2

[eluser]oddman[/eluser]
I haven't worked with CI validation yet, but is it possible to manually set error values for fields? If so, do your own custom validation and then simply assign the appropiate fields the errors when required.




Theme © iAndrew 2016 - Forum software by © MyBB