[eluser]Unknown[/eluser]
Hi
Yes. I'm kinda new to CodeIgniter as you'll see, but I'm having a big problem with validation of radios.
1. If I have a form with only radios in it, I can't get any validation to work. i.e <?=$this->validation->error_string;?> will not show anything on error
2. If I have more (text) field, <?=$this->validation->error_string;?> will appear, but the individual errors will appear, but not for the radios.
Have I missed something huge here? - Probably.
Example controller:
Code:
<?php
/**
* Testing how the form validation stuff works
*
*/
class Test extends Controller {
function __construct()
{
parent::Controller();
$this->load->helper(array('form', 'string','url'));
$this->load->library(array('validation'));
}
function index()
{
// validation info
$rules['review'] = 'trim|required|min_length[1]|max_length[10]';
$rules['review_name'] = 'trim|min_length[5]|max_length[10]';
$this->validation->set_rules($rules);
$fields['review'] = 'Review Id';
$fields['review_name'] = 'Review name';
$this->validation->set_fields($fields);
$this->validation->set_error_delimiters('<br/><em>[', ']</em>');
$data = array(); // Empty array
if ($this->validation->run() == FALSE)
{
// Load the review setup "Choose/Setup review" page (with validation messages when required)
$this->load->view('test', $data);
}
else
{
// Add a new review event
$this->load->view('test_success', $data);
}
}
}
?>
View:
Code:
<h2>Test/Example CI form validation</h2>
<?=$this->validation->error_string;?>
<?=form_open('test'); ?>
<p>
review_id <input type="radio" name="review" value="abc" <?= $this->validation->set_radio('review', 'abc'); ?> /><br/>
review_id <input type="radio" name="review" value="def" <?= $this->validation->set_radio('review', 'def'); ?> />
<?=$this->validation->review_error; ?>
</p>
<p>
review_name <input type="text" name="review_name" value="<?=$this->validation->review_name?>" />
<?=$this->validation->review_name_error; ?>
</p>
<p class="formFooter">
<input type="reset" value="reset" />
<input type="submit" value="<?=$this->lang->line('button_next')?>" />
</p>
</form>
I can't get <?=$this->validation->review_error; ?> to output anything.
Where am I going wrong?
Cheers
RH