dsvyc66464 2015-07-21 19:04
浏览 112
已采纳

使用Bootstrap验证来验证表单字段

I hope you all can give me a push in the right direction. I am creating a form using html/css & bootstrap. The form works kind of but I would like to use the validation states bootstrap offers. How do I use this in the right way? A field only should go green when it's correctly filled and red when an error occurs.

Can anyone give me an example on how I can show the correct state? (so green when correctly filled, red when not)

<div class="container">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="row">
<div class="col-xs-3" style="padding-right:5px;">
  <label for="ex1"  ></label>
  <input class="form-control inputForm" id="ex1" name="voornaam" type="text" placeholder="Voornaam">
</div>
<div class="col-xs-3" style="padding-left:5px;">
  <label for="ex2"></label>
  <input class="form-control inputForm" id="ex2" type="text" name="achternaam" placeholder="Achternaam">   </div> </div><div class="row">


<div class="col-xs-6">
  <label for="ex3"></label>
  <input class="form-control inputForm" id="ex3" name="email" type="text" placeholder="Voer je e-mailadres in">

  </div></div>

<div class="row">


<div class="col-xs-6">
  <label for="ex3"></label>
  <input class="form-control inputForm" id="ex3"  name="wachtwoord" type="password" placeholder="Wachtwoord">
</div></div>

<div class="row">


<div class="col-xs-6">

  <input class="btn btn-primary btn-lg active" type="submit"  value="Registeren" style="Float: right; margin-top: 15px; width: 100%;">
</div></div>
</form>
</div>
  • 写回答

1条回答 默认 最新

  • dronthpi05943 2015-07-21 19:33
    关注

    Use classes .has-warning, .has-error, or .has-success.

    Error state:

    <input class="form-control inputForm has-error" id="ex1" name="voornaam" type="text" placeholder="Voornaam">
    

    Correct state:

    <input class="form-control inputForm has-success" id="ex1" name="voornaam" type="text" placeholder="Voornaam">
    

    http://getbootstrap.com/css/#forms-control-validation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况