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

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

报告相同问题?

悬赏问题

  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?