Reputation: 12327
Hi i want to edit my validation_errors function that it will always have a div around it. Im using bootstrap and there is a nice way to show errors with Dismissable alerts Look here
I have found the function validation_errors() in system/helpers/form_helper.php which looks like:
if ( ! function_exists('validation_errors'))
{
function validation_errors($prefix = '', $suffix = '')
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
return '';
}
return $OBJ->error_string($prefix, $suffix);
}
}
How can i edit it that it returns :
<div class="alert alert-danger alert-dismissable">
errors here
</div>
I know i shouldn't do it in a helper class because its bad when i update my codeigniter version, but i really do not know how it can be done in a diffrent way.
Upvotes: 0
Views: 122
Reputation: 4211
Have you tried
if ( ! function_exists('validation_errors'))
{
function validation_errors($prefix = '', $suffix = '')
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
return '';
}
return '<div class="alert alert-danger alert-dismissable">'.$OBJ->error_string($prefix, $suffix).'</div>'
}
}
or
<?php
if(!empty(validation_errors())) {
echo '<div class="alert alert-danger alert-dismissable">'.validation_errors().'</div>';
}
?>
or if you really need to modify the helper
if ( ! function_exists('validation_errors'))
{
function validation_errors($prefix = '', $suffix = '')
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
return '';
}
if($OBJ->error_string($prefix, $suffix) != '') {
return '<div class="alert alert-danger alert-dismissable">'.$OBJ->error_string($prefix, $suffix).'</div>';
}
else {
return '';
}
}
}
Upvotes: 2