Welcome Guest, Not a member yet? Register   Sign In
How to use if statement with valication_errors()?
#1

[eluser]shinokada[/eluser]
I can use this.

Code:
if ($this->session->flashdata('msg')){ //change!
    echo "<div class='message'>";
    echo $this->session->flashdata('msg');
    echo "</div>";

But I can't use like this.

Code:
if (isset($this->validation_errors()){
    echo "<div class='message'>";
    echo validation_errors();
    echo "</div>";
}

How can I use if statement with valication_errors()?
#2

[eluser]Twisted1919[/eluser]
You can always do like
Code:
$errors = validation_errors();
if( !empty($errors) && strlen($errors) > X )
{
echo $errors ;
}
#3

[eluser]shinokada[/eluser]
Thanks.

I changed X to 0.

It works now.
#4

[eluser]Aken[/eluser]
Why exactly would you need to do this? The validation_errors() function will automatically do nothing if there are no errors to show, and you can set your own HTML wrapper around each error message through the form_validation class.
#5

[eluser]shinokada[/eluser]
Because of "<div class='message'>".

This div has a colour box to get attention.

I want to highlight the errors. Otherwise it won't be noticed.

If I add this div outside, it will be a empty colour box.




Theme © iAndrew 2016 - Forum software by © MyBB