فرمهای پایه
ساخت فرمهای ورودی اطلاعات با مهمترین فیلدها.
ساختار فرم
HTML
<form action="/submit" method="post">
<!-- فیلدها اینجا -->
<button type="submit">ارسال</button>
</form>
action— آدرسی که دادهها به آن ارسال میشوندmethod— معمولاًgetیاpost
برچسب (label)
همیشه فیلدها را با <label> مرتبط کنید. دو روش وجود دارد:
HTML
<!-- روش ۱: for و id -->
<label for="name">نام:</label>
<input type="text" id="name" name="name">
<!-- روش ۲: پیچیدن فیلد داخل label -->
<label>
نام:
<input type="text" name="name">
</label>
انواع input پرکاربرد
HTML
<input type="text" placeholder="نام شما">
<input type="email" placeholder="ایمیل">
<input type="password" placeholder="رمز عبور">
<input type="number" min="1" max="100">
<input type="tel" placeholder="۰۹۱۲...">
<input type="url" placeholder="https://">
<input type="date">
<input type="search" placeholder="جستجو...">
<input type="checkbox" id="agree">
<label for="agree">قوانین را میپذیرم</label>
<input type="radio" name="gender" value="male" id="m">
<label for="m">مرد</label>
<input type="radio" name="gender" value="female" id="f">
<label for="f">زن</label>
<input type="file">
<input type="hidden" name="token" value="abc123">
متن چندخطی و دکمه
HTML
<label for="msg">پیام:</label>
<textarea id="msg" name="message" rows="4" cols="40"></textarea>
<button type="submit">ارسال</button>
<button type="reset">پاک کردن</button>
<button type="button">دکمه معمولی</button>
مثال زنده فرم ساده
تمرین
تمرین: یک فرم ثبتنام بسازید که شامل نام، ایمیل، رمز عبور، تأیید رمز و چکباکس پذیرش قوانین باشد.