بوت استرپ سه طرح فرم فراهم میکند:

  • فرم عمومی
  • فرم افقی
  • فرم های درون خطی یا (Inline form)

قوانین و استاندارد برای هر سه فرم:

۱٫همیشه باید از کد <form role=”form”> استفاده کرد.

۲٫قرار دادن برچسب و کنترل فرم در <div class=”form-group”>

۳٫اضافه کردن کلاس .form-control به تمامی متن های <input>, <textarea>و <select>

۱٫Bootstrap Vertical Form (default)

نمونه کد زیر شامل یک فرم عمودی با دو رشته ورودی,یک چک باکس و یک دکمه برای ارسال فرم :

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link rel=”stylesheet” href=”http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css”>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”></script>
<script src=”http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js”></script>
</head>
<body>

<div class=”container”>
<h2>Vertical (basic) form</h2>
<form role=”form”>
<div class=”form-group”>
<label for=”email”>Email:</label>
<input type=”email” class=”form-control” id=”email” placeholder=”Enter email”>
</div>
<div class=”form-group”>
<label for=”pwd”>Password:</label>
<input type=”password” class=”form-control” id=”pwd” placeholder=”Enter password”>
</div>
<div class=”checkbox”>
<label><input type=”checkbox”> Remember me</label>
</div>
<button type=”submit” class=”btn btn-default”>Submit</button>
</form>
</div>

</body>
</html>

۲٫Bootstrap Inline Form

افزودن کلاس form-inline. در تگ <form>

نمونه کد زیر شامل دو رشته ورودی,یک چک باکس و یک دکمه برای ارسال فرم:

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link rel=”stylesheet” href=”http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css”>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”></script>
<script src=”http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js”></script>
</head>
<body>

<div class=”container”>
<h2>Inline form</h2>
<p>Make the viewport larger than 768px wide to see that all of the form elements are inline, left aligned, and the labels are alongside.</p>
<form class=”form-inline” role=”form”>
<div class=”form-group”>
<label for=”email”>Email:</label>
<input type=”email” class=”form-control” id=”email” placeholder=”Enter email”>
</div>
<div class=”form-group”>
<label for=”pwd”>Password:</label>
<input type=”password” class=”form-control” id=”pwd” placeholder=”Enter password”>
</div>
<div class=”checkbox”>
<label><input type=”checkbox”> Remember me</label>
</div>
<button type=”submit” class=”btn btn-default”>Submit</button>
</form>
</div>

</body>
</html>