PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 19, 2022

[FIXED] How To Bootstrap Integrate with Codeigniter Form Validation

 February 19, 2022     codeigniter, twitter-bootstrap, validation     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing