How do I define text field as required (with red border) in Twitter Bootstrap 3?
required="required"
doesn't work...
<form role="form"> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email"> </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <div class="form-group"> <label for="exampleInputFile">File input</label> <input type="file" id="exampleInputFile"> <p class="help-block">Example block-level help text here.</p> </div> <div class="checkbox"> <label> <input type="checkbox"> Check me out </label> </div> <button type="submit" class="btn btn-default">Submit</button> </form>
How to indicate a required field. Provide the required text in the label. Provide a graphic * image in the label with appropriate alt text. Providing a star (asterisk) symbol.
Yes. In your form builder account, click on any field in your Form Editor to open its Edit Field panel on the left side of the page. Tick the checkbox Required field and an asterisk will appear next to the label of the form field. The field is now required and visitors can't submit the form without filling it in.
If you want to make required fields on a form, all you have to do is add required="required" in the <input> tags.
Try using required="true"
in bootstrap 3
Update 2018
Since the original answer HTML5 validation is now supported in all modern browsers. Now the easiest way to make a field required is simply using the required attibute.
<input type="email" class="form-control" id="exampleInputEmail1" required>
or in compliant HTML5:
<input type="email" class="form-control" id="exampleInputEmail1" required="true">
Read more on Bootstrap 4 validation
In Bootstrap 3, you can apply a "validation state" class to the parent element: http://getbootstrap.com/css/#forms-control-validation
For example has-error
will show a red border around the input. However, this will have no impact on the actual validation of the field. You'd need to add some additional client (javascript) or server logic to make the field required.
Demo: http://bootply.com/90564
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With