简体   繁体   English

使用内置样式的Bootstrap 3表单验证

[英]Bootstrap 3 Form Validation Using built-in Styles

I would like to implement form validation using Bootstrap3's CSS (For Example: On Submit, assuming all forms are filled in correctly, display an "alert alert-success". If failed, display "alert alert-danger" containing an explanation to the failure (Ex: Please enter a valid name). Right now, all I can get to work is requiring text in a field (using HTML5 required tag) without the ability to display any alerts. 我想使用Bootstrap3的CSS来实现表单验证(例如:在Submit上,假设所有表单都正确填写,则显示“ alert alert-success”。如果失败,则显示“ alert alert-danger”,其中包含对失败的解释) (例如:请输入一个有效的名称。)现在,我所能做的就是要求字段中的文本(使用HTML5必需标记)而无法显示任何警报。

Current Code: http://pastebin.com/AjfUA26n 当前代码: http//pastebin.com/AjfUA26n

Website: http://infenterprises.com/contact/ 网站: http//infenterprises.com/contact/

You will need to do two things: 您将需要做两件事:

  1. Do server side validation. 做服务器端验证。 Client side validation can be a nice help for your user, but it doesn't replace server side validation for security reasons. 客户端验证可以为您的用户提供很好的帮助,但是出于安全原因,它不能代替服务器端验证。 That being said 话虽如此
  2. you will need to use Javascript to do client side validation and display the result. 您将需要使用Javascript进行客户端验证并显示结果。 A nice helper when using bootstrap is http://bootstrapvalidator.com/ . 使用引导程序时,一个很好的帮助是http://bootstrapvalidator.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM