Welcome Guest, Not a member yet? Register   Sign In
Simple customising of the 'Validation_errors' message
#1

[eluser]invision[/eluser]
Hi,

I'm currently using the following to display form errors on my forms:

Code:
&lt;?php echo validation_errors('<p class="error" style="background:red;border-bottom:1px solid black">'); ?&gt;

However, I want to display all errors within the ONE <p class="error"> and not repeat this for every error.


Many thanks for any help given.
#2

[eluser]Bas Vermeulen[/eluser]
Hi,

Code:
<div class="error" style="background:red;border-bottom:1px solid black">
&lt;?php echo validation_errors(); ?&gt;  
</div>

Is this what you mean?
#3

[eluser]invision[/eluser]
Yes, but I don't want to display the <div class="error"> unless there are actual errors after submission.

Is this possible?
#4

[eluser]Bas Vermeulen[/eluser]
Sure, this should work:

Code:
&lt;?php if(!empty($this->form_validation->_error_array)):?&gt;
    <div class="error" style="background:red;border-bottom:1px solid black">
        &lt;?php echo validation_errors(); ?&gt;  
    </div>  
&lt;?php endif; ?&gt;
#5

[eluser]invision[/eluser]
Back of the net!

The more I do CI, the more I'm picking it up.


Thanks for all your help
#6

[eluser]invision[/eluser]
Oh and just a quick PS.

How would you recommend I add a red border to any input field with incorrect input?

Is there a way to do this with CI?


Thanks so much again
#7

[eluser]Bas Vermeulen[/eluser]
You're welcome, happy to help out.

Yeah, the following will do that:

Code:
&lt;input type="text" name="input_name_here" id="input_name_here" value="&lt;?php echo set_value('input_name_here'); ?&gt;"&lt;?php if(isset($this-&gt;form_validation->_error_array['input_name_here'])): ?&gt;style="border: 1px solid red" &lt;?php endif; ?&gt;  />

Instead of setting the style like shown you ofc should set a class Wink
#8

[eluser]invision[/eluser]
Of course, that'll speed things up in the long run.

Thanks again for all your help kind sir.
#9

[eluser]Bas Vermeulen[/eluser]
No problem Wink
#10

[eluser]Dennis Rasmussen[/eluser]
This can do the job as well.

Code:
&lt;?php if(validation_errors()):?&gt;
    <div class="error" style="background:red;border-bottom:1px solid black">
        &lt;?php echo validation_errors(); ?&gt;  
    </div>  
&lt;?php endif; ?&gt;
Code:
&lt;input type="text" name="input_name_here" id="input_name_here" value="&lt;?php echo set_value('input_name_here'); ?&gt;"&lt;?php if(form_error('input_name_here')): ?&gt;style="border: 1px solid red" &lt;?php endif; ?&gt;  /&gt;




Theme © iAndrew 2016 - Forum software by © MyBB