0

I'm using CodeIgniter's Form Validation class to validate a form. In this form I have about 200 checkboxes of countries. I want to validate that the array of countries are all valid. I do this by checking if the array values correspond to actual country ID's in my database. The problem i have is that codeIgniter's Form Validation validates each of the 200 countries in the array which causes 200 query's against the database taking about 10 seconds to complete. Is there anyway to make CodeIgniter validate the entire array once?

1 Answer 1

2

You can bypass CodeIgniter's form validation and load all your countries from the database in one array, and the form values in another. Then you can use array_diff to see if there are values in the form values that don't appear in the database:

$should_be_empty = array_diff($form_array, $database_array);

$should_be_empty will be empty if there are no values in $form_array that don't appear in the database array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.