PHP Question

Style CodeIgniter "human name" in form validation

I want to apply custom general style to all the "human names" in the CodeIgniter

method of the form validation class:

$this->form_validation->set_rules(<name of field>, <human name>, <rules>);

Say I want to make all "human names" in boldface, I know that I can do:

$this->form_validation->set_rules(<name of field>, <strong>human name</strong>, <rules>);

However this is difficult to manage once the number of fields to style gets larger.

Is there are way to access it using something like the

$this->form_validation->set_error_delimeters('<div class="error">', '</div>');

wherein I can just set the delimeters for this "human name" or 2nd parameter in the

Currently there is no (at least explicitly discussed) way to do this from the documentation.

Answer Source

You want to change the error delimiters of the human name?

You want this change made in the extended form_validation class so you don't have to declare it again in all your validation classes?

If both yes, Chris has your back with this great solution!

class MY_Form_validation extends CI_Form_validation {

    public function __construct()

        $this->_error_prefix = '<p class="error">';
        $this->_error_suffix = '</p>';

This does not have to use the protected $CI magic thing so we are good here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download