CodeIgniter Forums
validation errors output - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: validation errors output (/showthread.php?tid=2339)



validation errors output - El Forum - 07-30-2007

[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.

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



validation errors output - El Forum - 07-30-2007

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



validation errors output - El Forum - 07-30-2007

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

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.


validation errors output - El Forum - 07-31-2007

[eluser]kirkaracha[/eluser]
I display the errors at the top of my form views like this:
Code:
&lt;?php if(isset($page_type) && $page_type=='form'){
    $this->load->view('shared/display_error_messages',$data);
    // 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:
Code:
&lt;?php
if(isset($this->validation->error_string)){
    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;
    }
}
?&gt;



validation errors output - El Forum - 07-31-2007

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