Welcome Guest, Not a member yet? Register   Sign In
dynamic input field array validation.
#1

I have  dynamic input field like this

PHP Code:
<input type="text" name="fault[0]" placeholder="" class="form-control name_list" /> 

this field can be increment like fault[1], fault[2], fault[3].......fault[10]  as many as the user willing to add the fields. how can i set validation rule for this?

code example please.
Reply
#2

note the brackets after the field name value

PHP Code:
       $formrules = array(
           array(
               'field' => 'fault[]',
               'label' => 'the fault field',
               'rules' => 'trim|max_length[40]'
           ),
 
       // and whatever else you need 
 
       );
        $this->form_validation->set_rules($formrules);

       if ($this->form_validation->run() == true)
       {return true; }
       else
       
{ return false; } 
Reply
#3

(08-09-2016, 06:41 PM)cartalot Wrote: note the brackets after the field name value

PHP Code:
       $formrules = array(
           array(
               'field' => 'fault[]',
               'label' => 'the fault field',
               'rules' => 'trim|max_length[40]'
           ),
 
       // and whatever else you need 
 
       );
        $this->form_validation->set_rules($formrules);

       if ($this->form_validation->run() == true)
       {return true; }
       else
       
{ return false; } 

Thanks mate this works.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB