I am trying to use Form Validation with an Array for field names. I was hoping that it was possible to validate each field individually, I've followed the documentation closely but I when I submit the form the validation message should display for one field but it displays for all fields. What have I done wrong?
View:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form method="post">
<input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>">
<?php echo form_error('options[]'); ?>
<br>
<input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>">
<?php echo form_error('options[]'); ?>
<br>
<input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>">
<?php echo form_error('options[]'); ?>
<br>
<input type="submit">
</form>
</body>
</html>
Controller Method:
PHP Code:
public function array_validation()
{
$this->load->helper( 'form' );
$this->load->library('form_validation');
$this->form_validation->set_rules('options[]', 'Options', 'trim|numeric');
if ($this->form_validation->run() == FALSE) {
// form empty or validation failed
} else {
}
$this->load->view('welcome/array_validation');
}