I'm using a form, inside which contains a div with a pair of input field which is added dynamically.
VIEW:
<?php echo form_open_multipart('location/add'); ?>
<div>
<input type="text" name="title[]"/>
<div id="infoMessage"><?php echo form_error('title[]'); ?></div>
</div>
<div>
<input type="text" name="desc[]"/>
<div id="infoMessage"><?php echo form_error('desc[]'); ?></div>
</div>
<div>
<input type="text" name="link[]"/>
<div id="infoMessage"><?php echo form_error('link[]'); ?></div>
</div>
<input type="submit" name="" value="enter">
<?php echo form_close(); ?>
Now, Initially I don't want validation for this 3 input fields but I want the backend validation for all the input fields that are going to add dynamically(by clicking on +
) on pressing submit button.
CONTROLLER:
public function add()
{
$this->form_validation->set_rules('title[]','Title','required');
$this->form_validation->set_rules('desc[]','Description','required');
$this->form_validation->set_rules('link[]','Link','required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('test');
}
else
{
....
}
}