CI_Form_validation::error PHP Method

error() public method

Gets the error message associated with a particular field
public error ( string $field, string $prefix = '', string $suffix = '' ) : string
$field string Field name
$prefix string HTML start tag
$suffix string HTML end tag
return string
    public function error($field, $prefix = '', $suffix = '')
    {
        if (empty($this->_field_data[$field]['error'])) {
            return '';
        }
        if ($prefix === '') {
            $prefix = $this->_error_prefix;
        }
        if ($suffix === '') {
            $suffix = $this->_error_suffix;
        }
        return $prefix . $this->_field_data[$field]['error'] . $suffix;
    }

Usage Example

 function error($field = '', $prefix = '', $suffix = '')
 {
     if (!empty($this->_field_data[$field]) && $this->_field_data[$field]['is_array']) {
         return ($prefix ? $prefix : $this->_error_prefix) . array_shift($this->_field_data[$field]['error']) . ($suffix ? $suffix : $this->_error_suffix);
     }
     return parent::error($field, $prefix, $suffix);
 }
All Usage Examples Of CI_Form_validation::error