Welcome Guest, Not a member yet? Register   Sign In
validation errors output

[eluser]Bacteria Man[/eluser]
Here's a simple tip, which might save somebody a couple of minutes.

The default output of each validation error is wrapped in paragraph tags. I wanted to use list item tags.

Fortunately the Validation class defines two properties, _error_prefix and _error_suffix, which makes it easy to change them. Create an extended class (if you haven't previously done so) and define the new values in the Constructor.

class My_Validation extends CI_Validation
     * Constructor
    function My_Validation()
        $this->_error_prefix = '<li>';
        $this->_error_suffix = '</li>';

[eluser]Michael Wales[/eluser]
Doesn't the following code work?
$this->validation->set_error_delimiters('<li>', '</li>');

[eluser]Bacteria Man[/eluser]
[quote author="walesmd" date="1185855961"]Doesn't the following code work?
$this->validation->set_error_delimiters('<li>', '</li>');

Yeah, sure, if you want to do it the easy way. :-)

Thanks... same difference actually, but I completely missed that function. Rick didn't miss a trick.

I display the errors at the top of my form views like this:
&lt;?php if(isset($page_type) && $page_type=='form'){
    // don't show the required fields notice on deletion confirmation forms
    if(!strpos($page_title,'delete')) {
        echo '<p class="note"><strong>Bold</strong> fields are required.</p>' . "\r\r";
} ?&gt;
The shared/display_error_messages view:
    if(count($this->validation->_error_array) > 0) {
        $display = '<div id="errors">' . "\r\r";
        $display .= "<p>Sorry, we had some trouble with your form.</p>\r\r";
        $display .= "<ul>\r";
        $display .= $this->validation->error_string;
        $display .= "</ul>\r";
        $display .= "</div>\r\r";

        echo $display;

[eluser]Bacteria Man[/eluser]
Thanks for sharing your snippet. I'm going to do something global like that.

Theme © iAndrew 2016 - Forum software by © MyBB