Welcome Guest, Not a member yet? Register   Sign In
help with Form Validation
#1

[eluser]GSV Sleeper Service[/eluser]
ok, what am I doing wrong?
I can't for the life of me figure out how to get set_radio() to work.

Code:
//controller snippet
$rules = array(
    array(
        'field' => 'compression',
        'label' => 'Compression',
        'rules' => 'required'
    )
);
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == FALSE)
{
    $this->load->view('myform');
}
else
{
    $this->load->view('formsuccess');
}

//snippet from 'myform' view
<?=form_label('Do you wish for all the files to be compressed (zipped)?','compression');?>
   <?=form_radio(array('name'=>'compression','id'=>'compression'),'yes',set_radio('compression','yes',TRUE));?> Yes
               <?=form_radio(array('name'=>'compression','id'=>'compression'),'no',set_radio('compression','no'));?> No

that 'yes' radio button is never checked by default, it should be according to the docs.
any ideas?

right, I traced this through the helper into the form_validation library and found this.
Code:
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
    if ($default === TRUE AND count($this->_field_data) === 0)
    {
        return ' checked="checked"'; //this is never going to return as $this->_field_data contains the validation rules!
    }
    return '';// my call to set_radio() gets returned here
}
is this is a bug? it's never going to return ' checked="checked"' as $this->_field_data gets populated by the validation rules
#2

[eluser]InsiteFX[/eluser]
It's in the user guide.

Code:
$this->form_validation->set_rules('username', 'Username', 'callback_username_check');

form_checkbox()

Form HelperForm Validation

Enjoy
InsiteFX
#3

[eluser]GSV Sleeper Service[/eluser]
er, that has got nothing to do with my question.
#4

[eluser]GSV Sleeper Service[/eluser]
no one? fine, reporting this as a bug




Theme © iAndrew 2016 - Forum software by © MyBB