Welcome Guest, Not a member yet? Register   Sign In
dynamic input fields validation in codeigniter
#8

Wouter60's answer is the best solution offered so far. Another alternative would be to do something like this:

PHP Code:
$x 1;
do {
    if (
$this->input->post("ID{$x}_first_name") || $this->input->post("ID{$x}_last_name"/* check all of your fields */) {
        
$this->form_validation->set_rules("ID{$x}_first_name"'First Name''trim|required|max_length[50]');
        
$this->form_validation->set_rules("ID{$x}_last_name"'Last Name''trim|required|max_length[50]');
        
// etc.
    
} else {
        break; 
// you could set $x = 0; instead, but by using break, $x is set to 1 more than the number on the last set of fields you validated.
    
}
} while (++
$x 0); 
Reply


Messages In This Thread
RE: dynamic input fields validation in codeigniter - by mwhitney - 07-18-2016, 02:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB