• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form validation for field create with jquery

#1
Hi at all sorry for english, i am doing an invoice .
i have one row with input text  article name= 'article[1]' and input text quantity name= 'quantity[1]' .
With jquery i create a new row clicking a button for every click i add a row

the name of input are increase (f.e. article[2] and quantity[2] , article[3] and quantity[3])

How can i validate this value ,i want set required for this field ...
Reply

#2
You could try something like this:
(Not tested, probably full of bugs)
PHP Code:
$fields count($this->input->post());
for (
$i=1$i <= $fields; ++$i
{
    if ( ( ! empty(
$this->input->post('article'.$i)) AND ( ! empty($this->input->post('quantity'.$i)) )
    {
        
$this->form_validation->set_rule('article'.$i'Article '.$i'required');
        
$this->form_validation->set_rule('quantity'.$i'Quantity '.$i'required|integer');
    }


I think that should work. May not be the cleanest or neatest way to achieve this but it is one possible way.

Paul.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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