• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using form validation to validate the $post array

#1
Hi all

quick question

i have a form which has alot of fields which are labeled as item1 item1a item2 item2b item3 item3b ect all the way up to 52

they will all need to be validated with the same options can i use the $post array in the validation

$data = $this->input->post(NULL, TRUE);

$this->form_validation->set_rules($data, 'data', 'required');

if ($this->form_validation->run() == FALSE)
{
echo "fail";
}
else
{
echo "win";
}

so i can validate them all in one swoop rather than doing a separate line for each ?

many thanks

cbiz
Reply

#2
You can set your rules by a simple loop like that (untested but i should work).

PHP Code:
for ($i=1$i<=52$i++)
{
    
$this->form_validation->set_rules('item'.$i'Item : '.$i'required');


You need a logic inside for your labeling .. dont see a exact logic there item1, item1a .. then item2, item2b .. etc. or all item {number|number.b}?

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.