Welcome Guest, Not a member yet? Register   Sign In
Problem with validation & radios
#1

[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);            
        }
    }        
}

?&gt;

View:
Code:
<h2>Test/Example CI form validation</h2>

&lt;?=$this->validation->error_string;?&gt;


&lt;?=form_open('test'); ?&gt;

    <p>
        review_id &lt;input type="radio" name="review" value="abc" &lt;?= $this-&gt;validation->set_radio('review', 'abc'); ?&gt; /><br/>
        review_id &lt;input type="radio" name="review" value="def" &lt;?= $this-&gt;validation->set_radio('review', 'def'); ?&gt; />
        &lt;?=$this->validation->review_error; ?&gt;
    </p>
        
    <p>
        review_name &lt;input type="text" name="review_name" value="&lt;?=$this-&gt;validation->review_name?&gt;" />
        &lt;?=$this->validation->review_name_error; ?&gt;
    </p>
        
    <p class="formFooter">
        &lt;input type="reset" value="reset" /&gt;
        &lt;input type="submit" value="&lt;?=$this-&gt;lang->line('button_next')?&gt;" />
    </p>

&lt;/form&gt;

I can't get &lt;?=$this->validation->review_error; ?&gt; to output anything.

Where am I going wrong?

Cheers
RH
#2

[eluser]Unknown[/eluser]
Oops, sorry.

This seems to be a bug see http://ellislab.com/forums/viewthread/51989/ for a fix




Theme © iAndrew 2016 - Forum software by © MyBB