I display the form validation error in codeigniter as below:
<?php echo form_error('name', '<div class="form_error">', '</div>'); ?>
i want to do it so that if there is error, then it should print error, otherwise it should print the info div.
For example,
if form_error, then
<?php echo form_error('name', '<div class="form_error">', '</div>'); ?>
else
<div class="info">Your first and last name. </div>
As form_error is not just a simple variable that i can check if it is empty then print info. How can i do it? Thanks.
You can do something like this:
For form_error might not be a variable but it’s a function that returns a string. If the string is empty (NULL, FALSE, “”, 0, …), the if statement will fail (meaning there is no error) and the form_error(‘name’) won’t be called.