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

[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>';
    }
}
#2

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

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

[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;
#5

[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