Welcome Guest, Not a member yet? Register   Sign In
Validation module: if value isn't set, a corresponding error message will be empty
#1

[eluser]Unknown[/eluser]
It's actual for radio-button control (I think for check-box it will be the same, but I didn't check it).

It's easy to explain with help the example:
Code:
$rules = array(
'sex'=> 'trim|required',
);
$this->validation->set_rules($rules);

Code:
<?= form_radio(array('name'=>'sex','value'=>'m','checked'=>$sex=='m')); ?> Male
<?= form_radio(array('name'=>'sex','value'=>'f','checked'=>$sex=='f')); ?> Female
<?= $this->validation->sex_error; ?>

The sex radio-control doesn't have default value, so it can be post as undefined.
In this case the corresponding error variable $this->validation->sex_error; will be empty and user will not see any error message. However he will be back on the form like it requires his corrections.

I suggest to fix it with following part of code in 231 line (number of string is for CI v1.5.4):

Code:
$mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field];
$message = sprintf($line, $mfield);

// Set the error variable.  Example: $this->username_error
$error = $field.'_error';
$this->$error = $this->_error_prefix.$message.$this->_error_suffix;

code before changes in 231 line:

Code:
$field = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field];
$this->_error_array[] = sprintf($line, $field);

Actually this fix equals the code in 323 line.




Theme © iAndrew 2016 - Forum software by © MyBB