Issue
How to just add highlight has-error and or has-success to codeigniter inputs for validation check.
I know there are java scripts out there for bootstrap 3 validation. But I have tried most of them.
I have my codeigniter validations working fine but would like to be able to add class has-error to input if codeigniter validation error is on.
And remove class has-error if OK and add class has-success
I know it can be done with java script, but the ones I have come across add extra required message which I don't need.
I am just after inputs changing color because I all ready have codeigniter validation message.
Same sort of effect but just with php codeigniter.
<div class="form-group">
<label class="col-sm-2 control-label"><?php echo $entry_db_hostname; ?></label>
<div class="col-sm-10">
<input type="text" name="db_hostname" value="<?php echo $db_hostname; ?>" class="form-control" size="50"/>
<?php echo form_error('db_hostname', '<div class="text-danger">', '</div>'); ?>
</div>
</div>
Solution
in the controller or model where you have the form validation code add
$this->form_validation->set_error_delimiters('<div class="text-danger">', '</div>');
then to display an error message for a specific form field - for example a field called 'username' - put this in your form code near the form input.
<?php echo form_error('username'); ?>
OR if you want to display all the errors together like at the top of the form
<?php echo validation_errors(); ?>
all the details at: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html
Answered By - cartalot
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.