CodeIgniter Forums
set_error_delimiters for group of errors - 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: set_error_delimiters for group of errors (/showthread.php?tid=5194)



set_error_delimiters for group of errors - El Forum - 01-10-2008

[eluser]deadfrog[/eluser]
I just discovered CodeIgniter and I absolutely love it so far, hoping the community is as cool!

Now I searched the forum but can't find an answer to this, but I find that odd as surely I can't be the only one who needs it. I'm probably being a fool so apologies in advance.

If I run this:

Code:
$this->validation->set_error_delimiters('<div class="error">', '</div>');

I get this:

Code:
<div class="error">error 1</div>
<div class="error">error 2</div>

And so on. What I want to achieve is:

Code:
<div id="error">
<ul>
<li>error 1</li>
<li>error 2</li>
</ul>
</div>

But I don't want the page to render any of the code unless errors exist.

Hope someone can assist, and hope I didn't miss a previous post.

Cheers chaps,
Andy.


set_error_delimiters for group of errors - El Forum - 01-10-2008

[eluser]Pascal Kriete[/eluser]
How about doing
Code:
$this->validation->set_error_delimiters('<li>', '</li>');

And in your view you put:
Code:
&lt;?php if($this->validation->error_string != ''): ?&gt;
<div id="error">
<ul>
&lt;?= $this->validation->error_string?&gt;
</ul>
</div>
&lt;?php endif; ?&gt;



set_error_delimiters for group of errors - El Forum - 01-10-2008

[eluser]deadfrog[/eluser]
Well that was a million times easier than I thought, quite why I didn't think of trying that I do not know!!

Thanks a bunch mate Smile


set_error_delimiters for group of errors - El Forum - 01-10-2008

[eluser]pims[/eluser]
... or you can hack the Validation class, add two properties to the object, like for instance
Code:
var $_error_open_tag;
var $_error_close_tag;

and in the run method of the class, near line 361, write something like:
Code:
// Generate the error string
    $this->error_string .= $this->error_open_tag;
    foreach ($this->_error_array as $val)
    {
        $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n";
    }
   $this->error_string .= $this->error_close_tag;

That should do the trick, and you should be able to customize the tags in your controller.


set_error_delimiters for group of errors - El Forum - 01-10-2008

[eluser]Pascal Kriete[/eluser]
That works, although I would extend it, instead of making changes right in the class.