Chapterبەش 3 · Lectureوانە 3.3
HTML Forms Reviewپێداچوونەوەی فۆرمەکانی HTML
Everything you need to build forms before PHP handles them: action and method, labels, text and password fields, radio buttons, checkboxes, drop-down lists, text areas, HTML5 input types and attributes — with the lab forms corrected and the Sign Up homework solved.
هەموو ئەوەی پێویستە بۆ دروستکردنی پێش ئەوەی PHP مامەڵەیان لەگەڵ بکات: action و method، ، و ، ، ، ، ، جۆر و inputـی HTML5؛ تاقیگە ڕاستکراونەتەوە و ئەرکی ماڵەوەی Sign Up شیکراوەتەوە.
What you will learnچی فێر دەبیت
- Explain what the action and method attributes do, and when to use GET or POST.
- Build forms with labels, text and password fields, radio buttons, checkboxes, drop-down lists, text areas and submit buttons.
- Predict exactly which name=value pairs a form sends.
- Use the HTML5 input types and the attributes autofocus, min, max, placeholder and required.
- Explain why browser checks never replace validation in PHP.
- ڕوونی بکەیتەوە action و method چی دەکەن و کەی GET یان POST بەکاربهێنیت.
- دروست بکەیت بە ، ، ، ، ، ، و .
- بە وردی پێشبینی بکەیت کام جووتی name=value دەنێرێت.
- جۆرەکانی inputـی HTML5 و autofocus، min، max، placeholder و required بەکاربهێنیت.
- ڕوونی بکەیتەوە بۆچی پشکنینەکانی هەرگیز جێگەی لە PHPـدا ناگرنەوە.
Why forms matterبۆچی فۆرمەکان گرنگن
Form controls are used to collect information from the user. A may also contain text and other elements, such as headings and images. Every time you log in, sign up, search or write a comment, you fill in an HTML form.
بۆ کۆکردنەوەی زانیاری لە بەکارهێنەر بەکاردێن. دەتوانێت دەق و تریش لەخۆ بگرێت، وەک سەردێڕ و وێنە. هەر جارێک دەچیتە ژوورەوە، خۆت تۆمار دەکەیت، دەگەڕێیت یان لێدوانێک دەنووسیت، HTML پڕ دەکەیتەوە.
HTML only draws the form. When the user presses the submit button, the browser packs the data and sends it to the server, where a PHP program receives it. So the HTML you write here decides what PHP will get later. This lecture reviews the form material of Lecture 1 and Lab 1; the Forms and User Input chapter then handles the data with PHP.
HTML تەنها دەکێشێت. کاتێک بەکارهێنەر دادەگرێت، دراوەکان کۆ دەکاتەوە و دەیاننێرێت بۆ ، کە لەوێ PHP وەریان دەگرێت. بۆیە ئەو HTMLـەی لێرە دەینووسیت بڕیار دەدات PHP دواتر چی وەردەگرێت. ئەم وانەیە پێداچوونەوە بە بابەتی وانەی ١ و تاقیگەی ١دا دەکات؛ پاشان بەشی فۆرمەکان و نێوخستەی بەکارهێنەر بە PHP مامەڵە لەگەڵ دراوەکان دەکات.
Think of a paper application form at a university registration office. Each box has a label ("Name", "Date of birth"). When you finish, you hand the form to one particular office (the action). You can hand it over openly, so anyone in the queue can read it, or in a sealed envelope (the method: GET or POST).
بیر لە کاغەزی داواکاری بکەرەوە لە فەرمانگەی تۆمارکردنی زانکۆ. هەر چوارگۆشەیەک ناونیشانێکی هەیە («ناو»، «بەرواری لەدایکبوون»). کاتێک تەواو دەبیت، دەدەیتە ژوورێکی دیاریکراو (action). دەتوانیت بە ئاشکرا بیدەیت، بەشێوەیەک هەر کەسێک لە ڕیزەکەدا بتوانێت بیخوێنێتەوە، یان لەناو زەرفێکی داخراودا (method: GET یان POST).
Where the analogy stops workingسنووری ئەم نموونەیە
A clerk checks a paper form by hand. A browser can check only a few simple rules, and a user can switch them off, so the server must always check the data again.
فەرمانبەرێک کاغەزییەکە بە دەست دەپشکنێت. تەنها دەتوانێت چەند یاسایەکی سادە بپشکنێت و بەکارهێنەر دەتوانێت لایان ببات، بۆیە دەبێت هەمیشە دراوەکان دووبارە بپشکنێتەوە.
The form element: action and methodتوخمی form: action و method
Everything inside <form> … </form> belongs to one form. The opening tag usually has two attributes:
هەموو شتێک لەناو <form> … </form>دا هی یەک . دەستپێک زۆرجار دوو هەیە:
action() defines the action to be performed when the form is submitted. Normally the form data is sent to a web page on the server when the user clicks the submit button. In<form action="action_page.php">the data goes to a page calledaction_page.php, which contains a server-side script that handles the form data.methodsays how the data travels:getorpost. If you leave it out, the browser uses GET.
action() ئەو کارە دیاری دەکات کە کاتی ناردنی ئەنجام دەدرێت. بە شێوەی ئاسایی، کاتێک بەکارهێنەر کرتە لە دەکات، دراوەکانی دەنێردرێن بۆ لەسەر . لە<form action="action_page.php">دا دراوەکان دەچن بۆ بە ناویaction_page.php، کە تێدایە و مامەڵە لەگەڵ دراوەکانی دەکات.methodدەڵێت دراوەکان چۆن دەگوازرێنەوە:getیانpost. ئەگەر نەینووسیت، GET بەکاردەهێنێت.
<form action="action_page.php" method="post">
...
</form>The form element: action and methodتوخمی form: action و method
GET or POST?GET یان POST؟
| Questionپرسیار | GET | POST |
|---|---|---|
| Where the data goesدراوەکان دەچنە کوێ | In the URL, after ? (the )لەناو ، دوای ? () | Inside the request, not in the URLلەناو ، نەک لە |
| Visible in the address bar and history?لە و مێژوودا دەبینرێت؟ | Yesبەڵێ | Noنەخێر |
| Can be bookmarked or shared?دەتوانرێت پاشەکەوت یان هاوبەش بکرێت؟ | Yesبەڵێ | Noنەخێر |
| Good forباشە بۆ | Searches and filters that only read dataگەڕان و پاڵاوتن کە تەنها دراوە دەخوێننەوە | Passwords, sign-ups and anything that changes data، و هەر شتێک دراوە بگۆڕێت |
Here is exactly what the browser sends for the mailing-list form below, once with each method. Notice that @ is sent as %40: the browser encodes special characters.
ئەمە ڕێک ئەوەیە کە بۆ mailing-list ـی خوارەوە دەینێرێت، جارێک بە هەر شێوازێک. سەرنج بدە کە @ وەک %40 دەنێردرێت: پیتە تایبەتەکان دەگۆڕێت.
GET /mailinglist.php?username=Aram&email=aram%40example.com HTTP/1.1
Host: localhostPOST /mailinglist.php HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
username=Aram&email=aram%40example.comA first complete formیەکەم فۆرمی تەواو
This is the lecture's mailing-list form. It is correct HTML. Type it and look at each line:
ئەمە mailing-listـی وانەکەیە. HTMLـێکی دروستە. بینووسە و سەیری هەموو دێڕێک بکە:
<form action="/mailinglist.php" method="post">
<h3>Please add your name to Mailing lists</h3>
<label for="firstlast">Name:</label>
<input type="text" name="username" id="firstlast">
<br />
<label for="email">Email:</label>
<input type="text" name="email" id="email">
<br /><br />
<input type="submit" value="Submit">
</form>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<form action="/mailinglist.php" method="post">
<h3>Please add your name to Mailing lists</h3>
<label for="firstlast">Name:</label>
<input type="text" name="username" id="firstlast">
<br />
<label for="email">Email:</label>
<input type="text" name="email" id="email">
<br /><br />
<input type="submit" value="Submit">
</form>In this preview the Submit button does nothing; on a real server it would send the data to mailinglist.php.
لەم پێشبینینەدا دوگمەی Submit هیچ ناکات؛ لەسەر ڕاستەقینە دراوەکان دەنێرێت بۆ mailinglist.php.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
Send the data to
/mailinglist.phpwith POST.دراوەکان بە POST بنێرە بۆ
/mailinglist.php.- Lineدێڕی 3
<label for="firstlast">belongs to the field whoseidisfirstlast.<label for="firstlast">هی ئەو خانەیەیە کەidـەکەیfirstlastـە.- Lineدێڕی 4
name="username"is the key the server receives;idis only for the label (and CSS).name="username"ئەو کە وەری دەگرێت؛idتەنها بۆ (و CSS).- Lineدێڕی 5
<br />is a line break (old XHTML style;<br>is the same).<br />شکاندنی دێڕە (شێوازی کۆنی XHTML؛<br>هەمان شتە).- Lineدێڕی 9
The submit button.
valueis the text on the button..
valueئەو دەقەیە کە لەسەر دوگمەکە دەنووسرێت.
A first complete formیەکەم فۆرمی تەواو
Labels: name, id and forلەیبڵەکان: name، id و for
| Attribute | What it is forبۆ چییە | Must be unique?دەبێت تاقانە بێت؟ |
|---|---|---|
name | The key under which the value is sent (username=Aram). PHP reads it as $_POST['username'].ئەو لە ژێریدا دەنێردرێت (username=Aram). PHP وەک $_POST['username'] دەیخوێنێتەوە. | No: radio buttons in one group share a name.نەخێر: یەک گرووپ هەمان nameـیان هەیە. |
id | A unique name in the page, used by <label for> and by CSS.ناوێکی تاقانەیە لە ، کە <label for> و CSS بەکاری دەهێنن. | Yesبەڵێ |
for (on <label>)for (لەسەر <label>) | Points to the id of the field the label belongs to.ئاماژە بە idـی ئەو خانەیە دەکات کە هی ئەوە. | — |
A makes the form easier to use: clicking the label puts the cursor in the field (or ticks the box), and screen readers read the label aloud. You can also put the field inside the label; then for and id are not needed: <label>Email: <input type="email" name="email"></label>.
بەکارهێنانی ئاسانتر دەکات: کرتەکردن لە دەخاتە ناو خانەکە (یان چوارگۆشەکە نیشان دەکات) و بە دەنگی بەرز دەخوێننەوە. دەتوانیت خانەکە بخەیتە ناو ؛ ئەو کاتە پێویستت بە for و id نییە: <label>Email: <input type="email" name="email"></label>.
Form elements (controls)توخمەکانی فۆرم
Most form controls are made with the <input> element. Its type attribute decides what the browser draws. <input> is a void element: it has no closing tag. Every control that should send data needs a name.
زۆربەی بە <input> دروست دەکرێن. type بڕیار دەدات چی بکێشێت. <input> بەتاڵە: کۆتایی نییە. هەر کە دەبێت دراوە بنێرێت، پێویستی بە name هەیە.
One more type sends a value that the visitor never sees: type="hidden". Pages use it to carry information from one page to the next, for example the id of the record being edited (the CRUD application).
typeـێکی تر دەنێرێت کە سەردانکەر هەرگیز نایبینێت: type="hidden". لاپەڕەکان بەکاری دەهێنن بۆ گواستنەوەی زانیاری لە لاپەڕەیەکەوە بۆ لاپەڕەی دواتر، بۆ نموونە id ـی ئەو دەستکاری دەکرێت (بەرنامەی CRUD).
<input type="hidden" name="id" value="5">Form elements (controls)توخمەکانی فۆرم
Text and password fieldsخانەی دەق و خانەی تێپەڕەوشە
A is a one-line box for short text, such as a user name:
چوارگۆشەیەکی یەک دێڕییە بۆ دەقی کورت، وەک :
<label for="uname">User name:</label>
<input type="text" name="uname" id="uname">HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<label for="uname">User name:</label>
<input type="text" name="uname" id="uname">A looks the same, but it shows dots instead of the letters you type:
هەمان شێوەی هەیە، بەڵام لەبری ئەو پیتانەی دەینووسیت خاڵ پیشان دەدات:
<label for="password">Password:</label>
<input type="password" name="password" id="password">HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<label for="password">Password:</label>
<input type="password" name="password" id="password">Form elements (controls)توخمەکانی فۆرم
Radio buttons and checkboxesدوگمەکانی ڕادیۆ و چێکبۆکسەکان
let the user choose exactly one option from a group. All radio buttons with the same name form one group; choosing one clears the others. Each one needs its own value: that value is what is sent. Add checked to choose one in advance.
ڕێگە بە بەکارهێنەر دەدەن تەنها یەک هەڵبژاردە لە گرووپێک هەڵبژێرێت. هەموو کە هەمان nameـیان هەیە یەک گرووپن؛ هەڵبژاردنی یەکێکیان ئەوانی تر لادەبات. هەریەکەیان پێویستی بە valueـی خۆی هەیە: ئەو ئەوەیە کە دەنێردرێت. checked زیاد بکە بۆ ئەوەی پێشوەخت یەکێکیان هەڵبژێردرێت.
<p>Gender:</p>
<input type="radio" name="gender" value="male" id="male">
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female">
<label for="female">Female</label>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Gender:</p>
<input type="radio" name="gender" value="male" id="male">
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female">
<label for="female">Female</label>Click one, then the other: only one can be selected.
کرتە لە یەکێکیان بکە، پاشان لەوی تر: تەنها یەکێکیان دەتوانێت هەڵبژێردراو بێت.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-4
Same
name="gender", differentvalue. If Female is chosen, the browser sendsgender=female.هەمان
name="gender"،valueـی جیاواز. ئەگەر Female هەڵبژێردرێت،gender=femaleدەنێرێت.
let the user tick any number of options, or none. An unticked checkbox sends nothing; a ticked one sends its value (or on if it has no value).
ڕێگە بە بەکارهێنەر دەدەن هەر ژمارەیەک هەڵبژاردە نیشان بکات، یان هیچ. نیشاننەکراو هیچ نانێرێت؛ نیشانکراو valueـەکەی دەنێرێت (یان on ئەگەر valueـی نەبێت).
<p>Languages you speak:</p>
<input type="checkbox" name="lang[]" value="kurd" id="kurd" checked>
<label for="kurd">Kurdish</label>
<input type="checkbox" name="lang[]" value="arab" id="arab">
<label for="arab">Arabic</label>
<input type="checkbox" name="lang[]" value="eng" id="eng">
<label for="eng">English</label>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Languages you speak:</p>
<input type="checkbox" name="lang[]" value="kurd" id="kurd" checked>
<label for="kurd">Kurdish</label>
<input type="checkbox" name="lang[]" value="arab" id="arab">
<label for="arab">Arabic</label>
<input type="checkbox" name="lang[]" value="eng" id="eng">
<label for="eng">English</label>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
checkedticks this box in advance.name="lang[]"with[]lets PHP receive all ticked values as a list.checkedئەم چوارگۆشەیە پێشوەخت نیشان دەکات.name="lang[]"بە[]ڕێگە دەدات PHP هەموو نرخە نیشانکراوەکان وەک لیستێک وەربگرێت.
Shows a radio-button group where only one choice is allowed, a drop-down menu, and checkboxes.
نیشان دەدات کۆمەڵێک کە تەنها دەتوانیت یەکێکیان هەڵبژێریت، لەگەڵ و چەند .
Watch 5:50 to the end: radio buttons, drop-down and checkboxes
لە 5:50 تا کۆتایی سەیر بکە: ، و .
Form elements (controls)توخمەکانی فۆرم
Drop-down listsلیستەکانی هەڵبژاردن
A is made with <select>, and each choice with <option>. The selected attribute chooses an option in advance; in the lecture's example the closed list shows Sulaimani.
بە <select> دروست دەکرێت و هەر هەڵبژاردەیەک بە <option>. selected هەڵبژاردەیەک پێشوەخت هەڵدەبژێرێت؛ لە نموونەی وانەکەدا لیستە داخراوەکە Sulaimani پیشان دەدات.
<label for="city">City:</label>
<select name="cities" id="city">
<option>Erbil</option>
<option selected>Sulaimani</option>
<option>Duhok</option>
<option>Halabja</option>
<option>Kirkuk</option>
</select>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<label for="city">City:</label>
<select name="cities" id="city">
<option>Erbil</option>
<option selected>Sulaimani</option>
<option>Duhok</option>
<option>Halabja</option>
<option>Kirkuk</option>
</select>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4
selectedmakes Sulaimani the starting choice.selectedSulaimani دەکاتە هەڵبژاردەی سەرەتا.
These options have no value attribute, so the browser sends the option's text: cities=Sulaimani. Usually you give each option a short value, which is sent instead of the text:
ئەم هەڵبژاردانە valueـیان نییە، بۆیە دەقی هەڵبژاردەکە دەنێرێت: cities=Sulaimani. زۆرجار valueـێکی کورت دەدەیتە هەر هەڵبژاردەیەک، کە لەبری دەقەکە دەنێردرێت:
<select name="city">
<option value="erbil">Erbil</option>
<option value="sulaimani" selected>Sulaimani</option>
<option value="duhok">Duhok</option>
</select>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<select name="city">
<option value="erbil">Erbil</option>
<option value="sulaimani" selected>Sulaimani</option>
<option value="duhok">Duhok</option>
</select>Add multiple and the user can choose several options (Ctrl-click on Windows, Cmd-click on a Mac); size sets how many lines are visible. Give the name square brackets, so PHP receives all the choices as an array, as with checkboxes:
multiple زیاد بکە و دەتوانێت چەند بژاردەیەک هەڵبژێرێت (Ctrl لەگەڵ کرتە لە ویندۆز، Cmd لەگەڵ کرتە لە ماک)؛ size دیاری دەکات چەند دێڕ دیار بێت. کەوانەی چوارگۆشە بخە دوای ناوەکە، بۆ ئەوەی PHP هەموو هەڵبژاردنەکان وەک وەربگرێت، وەک چێکبۆکسەکان:
<label for="classes">Classes attended:</label>
<select name="classes[]" id="classes" multiple size="3">
<option value="geography">Geography</option>
<option value="mathematics">Mathematics</option>
<option value="english">English</option>
</select>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
classes[]: PHP gets$_POST["classes"]as an array, for example["geography", "english"].classes[]: PHP$_POST["classes"]وەک وەردەگرێت، بۆ نموونە["geography", "english"].
In Kurdish: how to make a drop-down list with select and option inside a form.
بە کوردی: چۆن بە <select> و <option> لەناو دروست بکەیت.
Whole video: Kurdish explanation of select and option
هەموو ڤیدیۆکە: ڕوونکردنەوەی <select> و <option> بە کوردی.
Form elements (controls)توخمەکانی فۆرم
Text areas and submit buttonsناوچەکانی دەق و دوگمەکانی ناردن
A is a box for several lines of text, such as a biography or a comment. Unlike <input>, it has a closing tag, and any starting text goes between the tags. rows and cols set its size.
چوارگۆشەیەکە بۆ چەند دێڕێک دەق، وەک ژیاننامە یان لێدوانێک. بە پێچەوانەی <input>، کۆتایی هەیە و هەر دەقێکی سەرەتایی دەچێتە نێوان . rows و cols قەبارەکەی دیاری دەکەن.
<label for="bio">Biography:</label><br>
<textarea name="bio" id="bio" rows="4" cols="40"></textarea>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<label for="bio">Biography:</label><br>
<textarea name="bio" id="bio" rows="4" cols="40"></textarea>The sends the form. You can make it with <input type="submit"> (the value is the button text) or with <button type="submit">, which can contain any content between its tags. Both do the same job:
دەنێرێت. دەتوانیت بە <input type="submit"> دروستی بکەیت (value دەقی سەر دوگمەکەیە) یان بە <button type="submit">، کە دەتوانێت هەر ناوەڕۆکێک لە نێوان هەبێت. هەردووکیان هەمان کار دەکەن:
<input type="submit" value="Register">
<button type="submit">Register</button>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<input type="submit" value="Register">
<button type="submit">Register</button>Two more button types. type="reset" puts every field back to its first value; real forms rarely use it, because one wrong click deletes everything the user typed. type="button" (or <button type="button">) does nothing by itself: it is a button for JavaScript to use.
دوو جۆری تری دوگمە. type="reset" هەموو خانەیەک دەگەڕێنێتەوە بۆ سەرەتاکەی؛ ڕاستەقینە کەم بەکاری دەهێنن، چونکە یەک کرتەی هەڵە هەموو ئەوەی نووسیویەتی دەسڕێتەوە. type="button" (یان <button type="button">) خۆی هیچ ناکات: دوگمەیەکە بۆ ئەوەی بەکاری بهێنێت.
<input type="reset" value="Clear form">
<button type="button">Show more</button> <!-- does nothing until JavaScript gives it a job -->| Control | Codeکۆد | What is sentچی دەنێردرێت |
|---|---|---|
| Text field | <input type="text" name="uname"> | uname= + typed textuname= + دەقی نووسراو |
| Password field | <input type="password" name="password"> | password= + typed textpassword= + دەقی نووسراو |
| Radio buttons | <input type="radio" name="gender" value="male"> | The value of the chosen onevalueـی ئەوەی هەڵبژێردراوە |
| Checkboxes | <input type="checkbox" name="lang[]" value="kurd"> | The value of each ticked boxvalueـی هەر چوارگۆشەیەکی نیشانکراو |
| Drop-down list | <select name="city"><option>…</option></select> | The chosen option's value (or its text)valueـی هەڵبژاردەی هەڵبژێردراو (یان دەقەکەی) |
| Text area | <textarea name="bio"></textarea> | bio= + typed textbio= + دەقی نووسراو |
| Submit button | <input type="submit" value="Send"> | Only if it has a nameتەنها ئەگەر nameـی هەبێت |
HTML5 input typesجۆرەکانی input لە HTML5ـدا
added several new values for type. On phones they bring the right keyboard, and many of them give a ready-made picker (a calendar, a colour chooser, a slider). Some also check the value before the form is sent. Here are all the types from the lecture, corrected, plus week:
چەند نرخێکی نوێی بۆ type زیاد کرد. لەسەر مۆبایل تەختەکلیلی گونجاو دەهێنن و زۆربەیان هەڵبژێرێکی ئامادە دەدەن (ڕۆژژمێر، هەڵبژاردنی ڕەنگ، خلیسکێنەر). هەندێکیشیان پێش ناردنی دەپشکنن. ئەمە هەموو جۆرەکانی وانەکەیە، ڕاستکراوە، لەگەڵ week:
| type | What the browser shows چی پیشان دەدات | Value sentئەو نرخەی دەنێردرێت |
|---|---|---|
color | A colour pickerهەڵبژێری ڕەنگ | #ff0000 |
date | A calendar to pick a dayڕۆژژمێرێک بۆ هەڵبژاردنی ڕۆژ | 2026-10-16 |
datetime-local | A date and a time (no time zone)بەروار و کات (بێ ناوچەی کات) | 2026-10-16T09:30 |
email | A text box that checks for an email address کە دەپشکنێت | aram@example.com |
month | A month and yearمانگ و ساڵ | 2026-10 |
number | A number box with up/down arrows; min, max, stepچوارگۆشەی ژمارە بە تیری سەرەوە/خوارەوە؛ min، max، step | 5 |
range | A slider (default 0 to 100)خلیسکێنەر (بە شێوەی بنەڕەتی 0 تا 100) | 7 |
search | A text box for searching (may show a clear ✕ button) بۆ گەڕان (لەوانەیە دوگمەی سڕینەوەی ✕ پیشان بدات) | the typed textدەقە نووسراوەکە |
tel | A text box with a phone keypad on mobiles (no format check) لەگەڵ تەختەکلیلی ژمارەی تەلەفۆن لەسەر مۆبایل (بێ پشکنینی شێوە) | 0750 000 0000 |
time | A timeکات | 09:30 |
url | A text box that checks for a full web address کە ناونیشانی تەواوی وێب دەپشکنێت | https://www.php.net |
week | A week of the yearهەفتەیەکی ساڵ | 2026-W42 |
<form>
<p><label>color: <input type="color" name="favcolor" value="#ff0000"></label></p>
<p><label>date: <input type="date" name="bday"></label></p>
<p><label>datetime-local: <input type="datetime-local" name="appointment"></label></p>
<p><label>email: <input type="email" name="email"></label></p>
<p><label>month: <input type="month" name="bdaymonth"></label></p>
<p><label>number: <input type="number" name="quantity" min="1" max="10"></label></p>
<p><label>range: <input type="range" name="point" min="0" max="10"></label></p>
<p><label>search: <input type="search" name="googlesearch"></label></p>
<p><label>tel: <input type="tel" name="usrtel"></label></p>
<p><label>time: <input type="time" name="usr-time"></label></p>
<p><label>url: <input type="url" name="homepage"></label></p>
<p><label>week: <input type="week" name="week"></label></p>
</form>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<form>
<p><label>color: <input type="color" name="favcolor" value="#ff0000"></label></p>
<p><label>date: <input type="date" name="bday"></label></p>
<p><label>datetime-local: <input type="datetime-local" name="appointment"></label></p>
<p><label>email: <input type="email" name="email"></label></p>
<p><label>month: <input type="month" name="bdaymonth"></label></p>
<p><label>number: <input type="number" name="quantity" min="1" max="10"></label></p>
<p><label>range: <input type="range" name="point" min="0" max="10"></label></p>
<p><label>search: <input type="search" name="googlesearch"></label></p>
<p><label>tel: <input type="tel" name="usrtel"></label></p>
<p><label>time: <input type="time" name="usr-time"></label></p>
<p><label>url: <input type="url" name="homepage"></label></p>
<p><label>week: <input type="week" name="week"></label></p>
</form>Each browser draws these controls in its own way. Firefox and Safari on a computer show month and week as plain text boxes.
هەر ئەم بە شێوەی خۆی دەکێشێت. Firefox و Safari لەسەر کۆمپیوتەر month و week وەک ئاسایی پیشان دەدەن.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
A label can wrap the input; then
for/idare not needed.دەتوانێت input لەخۆ بگرێت؛ ئەو کاتە پێویست بە
for/idناکات.- Lineدێڕی 7
minandmaxlimit the number.minوmaxژمارەکە سنووردار دەکەن.
Short, clear chapters on the HTML5 input types email, tel (phone), date and number.
چەند بەشێکی کورت و ڕوون دەربارەی جۆرە نوێیەکانی لە : email، tel (ژمارەی تەلەفۆن)، date و number.
Watch 6:16 to 10:46: email, phone, date and number inputs
لە 6:16 تا 10:46 سەیر بکە: بۆ ، تەلەفۆن، بەروار و ژمارە.
Important HTML5 attributesخەسڵەتە گرنگەکانی HTML5
autofocusputs the cursor in this field automatically when the page loads. Use it on one field only.minandmaxset the minimum and maximum values for an<input>, for example a number or a date.stepsets the jump between allowed values.placeholdershows a grey hint that describes the expected value. It disappears when the user starts typing.requiredmeans the field must be filled in before the form can be submitted (a ).
autofocusکاتێک دەکرێتەوە، خۆکارانە دەخاتە ناو ئەم خانەیە. تەنها لەسەر یەک خانە بەکاری بهێنە.minوmaxکەمترین و زۆرترین بۆ<input>ـێک دیاری دەکەن، بۆ نموونە ژمارە یان بەروار.stepماوەی نێوان ڕێگەپێدراوەکان دیاری دەکات.placeholderڕێنماییەکی خۆڵەمێشی پیشان دەدات کە چاوەڕوانکراو وەسف دەکات. کاتێک بەکارهێنەر دەست بە نووسین دەکات ون دەبێت.requiredواتە خانەکە دەبێت پێش ناردنی پڕ بکرێتەوە ().
<form action="register.php" method="post">
<label for="name">Name:</label>
<input type="text" name="name" id="name" placeholder="e.g. Aram" required>
<br><br>
<label for="age">Age:</label>
<input type="number" name="age" id="age" min="17" max="60" required>
<br><br>
<input type="submit" value="Register">
</form>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<form action="register.php" method="post">
<label for="name">Name:</label>
<input type="text" name="name" id="name" placeholder="e.g. Aram" required>
<br><br>
<label for="age">Age:</label>
<input type="number" name="age" id="age" min="17" max="60" required>
<br><br>
<input type="submit" value="Register">
</form>In a normal page, pressing Register with an empty name or an age of 70 shows a browser message and the form is not sent.
لە ئاساییدا، داگرتنی Register بە ناوێکی بەتاڵ یان تەمەنی 70، پەیامێکی پیشان دەدات و نانێردرێت.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
A hint inside the box, and the field cannot stay empty.
ڕێنماییەک لەناو چوارگۆشەکە و خانەکە ناتوانێت بەتاڵ بمێنێتەوە.
- Lineدێڕی 6
Only numbers from 17 to 60 are accepted.
تەنها ژمارەکانی 17 تا 60 قبووڵ دەکرێن.
<label for="search">Search:</label>
<input type="search" name="q" id="search" autofocus>required and autofocus are attributes: writing the name is enough to switch them on. They take no value, and any value means "on": even required="false" still makes the field required. To switch them off, leave them out. Attribute names are written in lowercase (the slide writes "Autofocus", "Placeholder").
required و autofocus : نووسینی ناوەکە بەسە بۆ چالاککردنیان. وەرناگرن و هەر واتە «چالاک»: تەنانەت required="false"یش خانەکە پێویست دەکات. بۆ ناچالاککردنیان، مەیاننووسە. ناوی بە پیتی بچووک دەنووسرێن (سلایدەکە «Autofocus» و «Placeholder» دەنووسێت).
Important HTML5 attributesخەسڵەتە گرنگەکانی HTML5
Suggestions and locked fields: datalist, readonly and disabledپێشنیار و خانەی داخراو: datalist، readonly و disabled
<datalist> gives a text field a list of suggestions while the user types. Link the two with the same name in the field's list and the datalist's id. Unlike <select>, the user may still type something that is not in the list.
<datalist> لیستێک پێشنیار دەداتە لە کاتێکدا دەنووسێت. ئەم دووانە بە هەمان ناو لە listـی خانەکە و idـی datalistـەکەدا بەیەکەوە ببەستە. بە پێچەوانەی <select>، هێشتا دەتوانێت شتێک بنووسێت کە لە لیستەکەدا نییە.
<label for="city">City:</label>
<input type="text" name="city" id="city" list="cities">
<datalist id="cities">
<option value="Erbil"></option>
<option value="Sulaymaniyah"></option>
<option value="Duhok"></option>
<option value="Halabja"></option>
</datalist>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<label for="city">City:</label>
<input type="text" name="city" id="city" list="cities">
<datalist id="cities">
<option value="Erbil"></option>
<option value="Sulaymaniyah"></option>
<option value="Duhok"></option>
<option value="Halabja"></option>
</datalist>Click the box or type "S": the browser suggests the cities.
کرتە لە خانەکە بکە یان «S» بنووسە: شارەکان پێشنیار دەکات.
Two attributes lock a field. With readonly the user can read and select the text but not change it, and the value is sent with the form (the lecture uses it for a terms-and-conditions box). With disabled the field is greyed out, cannot be used and is not sent at all.
دوو خانەیەک دادەخەن. بە readonly، دەتوانێت دەقەکە بخوێنێتەوە و دیاری بکات بەڵام ناتوانێت بیگۆڕێت و لەگەڵ دەنێردرێت (وانەکە بۆ سندووقی مەرج و ڕێساکان بەکاری دەهێنێت). بە disabled، خانەکە خۆڵەمێشی دەبێت، بەکار نایەت و هەرگیز نانێردرێت.
<textarea name="terms" rows="3" cols="40" readonly>Terms and conditions …</textarea>
<input type="text" name="code" value="A-17" disabled>Lab 1: practising formsتاقیگەی ١: ڕاهێنان لەسەر فۆرمەکان
Lab 1 practises forms in two steps: a basic registration form (Exercise three) and a login form (More example). The lab gives the code for both. Type each one, open it in the browser, and then compare it with the corrected version.
تاقیگەی ١ لە دوو هەنگاودا ڕاهێنان لەسەر دەکات: سادەی (ڕاهێنانی سێیەم) و (نموونەی زیاتر). تاقیگەکە کۆدی هەردووکیانی داوە. هەریەکەیان بنووسە، لە بیکەرەوە، پاشان لەگەڵ وەشانە ڕاستکراوەکەدا بەراوردی بکە.
Lab 1: practising formsتاقیگەی ١: ڕاهێنان لەسەر فۆرمەکان
Exercise three: a basic formڕاهێنانی سێیەم: فۆرمێکی سادە
"Form is used to collect information from the user. Write the following code." Here is the lab's code with the quotes corrected:
« بۆ کۆکردنەوەی زانیاری لە بەکارهێنەر بەکاردێت. ئەم کۆدەی خوارەوە بنووسە.» ئەمە کۆدی تاقیگەکەیە بە ڕاستکراوە:
<form action="" method="post">
<h3>please enter your name and email address</h3>
Name: <input type="text" name="uname"><br>
Email: <input type="text" name="email"><br>
<input type="submit" name="submit" value="register">
</form>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<form action="" method="post">
<h3>please enter your name and email address</h3>
Name: <input type="text" name="uname"><br>
Email: <input type="text" name="email"><br>
<input type="submit" name="submit" value="register">
</form>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
action=""sends the form back to the same page, with POST. Later, the PHP code on this page will read the data.action=""بە POST دەنێرێتەوە بۆ هەمان . دواتر کۆدی PHPـی ئەم دراوەکان دەخوێنێتەوە.- Lineدێڕی 5
The submit button has a
name, sosubmit=registeris sent too. PHP can use it to see that the form was submitted.nameـی هەیە، بۆیەsubmit=registerیش دەنێردرێت. PHP دەتوانێت بەکاری بهێنێت بۆ زانینی ئەوەی کە نێردراوە.
Lab 1: practising formsتاقیگەی ١: ڕاهێنان لەسەر فۆرمەکان
More example: a login form with fieldset, legend and placeholderنموونەی زیاتر: فۆرمێک چوونەژوورەوە لەگەڵ fieldset، legend و placeholder
<fieldset> draws a border around a group of related controls, and <legend> puts a title in that border. Here is the lab's code as it was given:
<fieldset> هێڵێک بە دەوری گرووپێک پەیوەندیدار دەکێشێت و <legend> ناونیشانێک دەخاتە ناو ئەو هێڵە. ئەمە کۆدی تاقیگەکەیە وەک خۆی:
<div style="margin-top:200px;background-color:navajowhite;margin-left: 300px;margin-right: 300px" align="center">
<form action="#">
<fieldset>
<legend>Login Information:</legend>
First name:<br>
<input type="text" name="firstname" placeholder="Your name">
<br>
Last name:<br>
<input type="password" name="lastname" placeholder="Password">
<br><br>
<input type="submit" value="LogIN">
</fieldset>
</form>
</div>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<div style="margin-top:200px;background-color:navajowhite;margin-left: 300px;margin-right: 300px" align="center">
<form action="#">
<fieldset>
<legend>Login Information:</legend>
First name:<br>
<input type="text" name="firstname" placeholder="Your name">
<br>
Last name:<br>
<input type="password" name="lastname" placeholder="Password">
<br><br>
<input type="submit" value="LogIN">
</fieldset>
</form>
</div>The fixed 300px side margins leave the orange box very little room on a narrow screen (like this preview), so the fieldset spills out of it. On a wide screen it looks like the picture in the lab sheet.
پەراوێزە جێگیرەکانی 300px لەسەر شاشەی تەسک (وەک ئەم پێشبینینە) شوێنێکی زۆر کەم بۆ چوارگۆشە پرتەقاڵییەکە دەهێڵنەوە، بۆیە fieldsetـەکە لێی دەڕژێتە دەرەوە. لەسەر شاشەی پان وەک وێنەکەی پەڕەی تاقیگەکە دەردەکەوێت.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
A light-orange (navajowhite) box with big fixed margins.
چوارگۆشەیەکی پرتەقاڵیی کاڵ (navajowhite) لەگەڵ پەراوێزی گەورەی جێگیر.
- Lineدێڕی 3-4
<fieldset>and its<legend>title.<fieldset>و ناونیشانی<legend>ـەکەی.- Lineدێڕی 6
placeholdershows the grey hint "Your name".placeholderڕێنماییە خۆڵەمێشییەکەی «Your name» پیشان دەدات.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Log in</title>
<style>
.box {
max-width: 420px;
margin: 40px auto;
background-color: navajowhite;
text-align: center;
}
</style>
</head>
<body>
<div class="box">
<form action="login.php" method="post">
<fieldset>
<legend>Login Information:</legend>
<label for="username">User name:</label><br>
<input type="text" name="username" id="username" placeholder="Your name"><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password" placeholder="Password"><br><br>
<input type="submit" value="Log in">
</fieldset>
</form>
</div>
</body>
</html>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Log in</title>
<style>
.box {
max-width: 420px;
margin: 40px auto;
background-color: navajowhite;
text-align: center;
}
</style>
</head>
<body>
<div class="box">
<form action="login.php" method="post">
<fieldset>
<legend>Login Information:</legend>
<label for="username">User name:</label><br>
<input type="text" name="username" id="username" placeholder="Your name"><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password" placeholder="Password"><br><br>
<input type="submit" value="Log in">
</fieldset>
</form>
</div>
</body>
</html>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 7-12
CSS replaces
alignand the fixed margins: at most 420px wide, centred.CSS جێگەی
alignو پەراوێزە جێگیرەکان دەگرێتەوە: زۆرترین پانی 420px، لە ناوەڕاست.- Lineدێڕی 17
POST, so the password is not shown in the URL.
POST، بۆ ئەوەی لە پیشان نەدرێت.
- Lineدێڕی 23
A real password field, with a matching label and a clear name.
ڕاستەقینە، لەگەڵ گونجاو و ناوێکی ڕوون.
Homework: the Sign Up formئەرکی ماڵەوە: فۆرمی Sign Up
The lab ends with a homework: "create the following form that shows in the image". No code is given; this is the only description:
تاقیگەکە بە ئەرکێکی ماڵەوە کۆتایی دێت: «ئەو دروست بکە کە لە وێنەکەدا دەردەکەوێت». هیچ کۆدێک نەدراوە؛ ئەمە تاکە وەسفەکەیە:
- Three
<fieldset>groups with backgrounds of roughly grey (silver), light blue (skyblue) and tan (burlywood). The exact colours are not given. - Group 1, legend "Your basic info": Name, Email, Password and Age (two radio buttons: Under 13, 13 or older).
- Group 2, legend "Your profile": Biography (a text area).
- Group 3, no legend: Job Role (a drop-down list; only "Front-End Developer" is visible) and Interests (checkboxes Development, Design, Business).
- A Sign Up submit button.
- In the picture the legends read "1Your basic info": the number was probably a styled badge whose CSS is missing. Add a small space or style for the number.
- سێ گرووپی
<fieldset>بە باکگراوندی نزیکەی خۆڵەمێشی (silver)، شینی کاڵ (skyblue) و قاوەیی کاڵ (burlywood). ڕەنگە ورددەکان نەدراون. - گرووپی ١، legend «Your basic info»: Name، Email، Password و Age (دوو : Under 13، 13 or older).
- گرووپی ٢، legend «Your profile»: Biography ().
- گرووپی ٣، بێ legend: Job Role (؛ تەنها «Front-End Developer» دیارە) و Interests ( Development، Design، Business).
- Sign Up.
- لە وێنەکەدا legendـەکان دەڵێن «1Your basic info»: ژمارەکە لەوانەیە نیشانەیەکی ڕازێنراو بووبێت کە CSSـەکەی نەماوە. بچووک یان شێوازێک بۆ ژمارەکە زیاد بکە.
Create the Sign Up form from the picture. Use fieldsets with legends, labels for every field, a radio group for the age, a text area, a drop-down list and checkboxes. Send it with POST to signup.php.
Sign Up لە وێنەکەوە دروست بکە. fieldset لەگەڵ legend، بۆ هەموو خانەیەک، گرووپێکی بۆ تەمەن، ، و بەکاربهێنە. بە POST بینێرە بۆ signup.php.
Hintئاماژە
Both age radio buttons need the same name. Give the checkboxes the name interests[].
هەردوو تەمەن پێویستیان بە هەمان name هەیە. ناوی interests[] بدە .
Show answerوەڵامەکە پیشان بدە
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
<style>
body { font-family: Georgia, serif; max-width: 560px; margin: 20px auto; }
fieldset { margin-bottom: 20px; padding: 8px 16px; border: 1px solid #777; }
legend { font-size: 1.3em; font-weight: bold; }
.number { margin-right: 6px; }
label { display: inline-block; margin: 6px 0; }
.basic { background: silver; }
.profile { background: skyblue; }
.job { background: burlywood; }
</style>
</head>
<body>
<h1>Sign Up</h1>
<form action="signup.php" method="post">
<fieldset class="basic">
<legend><span class="number">1</span>Your basic info</legend>
<label for="name">Name:</label>
<input type="text" name="name" id="name"><br>
<label for="email">Email:</label>
<input type="email" name="email" id="email"><br>
<label for="password">Password:</label>
<input type="password" name="password" id="password">
<p>Age:</p>
<input type="radio" name="age" value="under_13" id="under_13">
<label for="under_13">Under 13</label><br>
<input type="radio" name="age" value="13_or_older" id="older">
<label for="older">13 or older</label>
</fieldset>
<fieldset class="profile">
<legend><span class="number">2</span>Your profile</legend>
<label for="bio">Biography:</label>
<textarea name="bio" id="bio"></textarea>
</fieldset>
<fieldset class="job">
<label for="job">Job Role:</label><br>
<select name="job" id="job">
<option value="front-end">Front-End Developer</option>
<option value="back-end">Back-End Developer</option>
<option value="full-stack">Full-Stack Developer</option>
</select>
<p>Interests:</p>
<input type="checkbox" name="interests[]" value="development" id="development">
<label for="development">Development</label><br>
<input type="checkbox" name="interests[]" value="design" id="design">
<label for="design">Design</label><br>
<input type="checkbox" name="interests[]" value="business" id="business">
<label for="business">Business</label>
</fieldset>
<input type="submit" value="Sign Up">
</form>
</body>
</html>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
<style>
body { font-family: Georgia, serif; max-width: 560px; margin: 20px auto; }
fieldset { margin-bottom: 20px; padding: 8px 16px; border: 1px solid #777; }
legend { font-size: 1.3em; font-weight: bold; }
.number { margin-right: 6px; }
label { display: inline-block; margin: 6px 0; }
.basic { background: silver; }
.profile { background: skyblue; }
.job { background: burlywood; }
</style>
</head>
<body>
<h1>Sign Up</h1>
<form action="signup.php" method="post">
<fieldset class="basic">
<legend><span class="number">1</span>Your basic info</legend>
<label for="name">Name:</label>
<input type="text" name="name" id="name"><br>
<label for="email">Email:</label>
<input type="email" name="email" id="email"><br>
<label for="password">Password:</label>
<input type="password" name="password" id="password">
<p>Age:</p>
<input type="radio" name="age" value="under_13" id="under_13">
<label for="under_13">Under 13</label><br>
<input type="radio" name="age" value="13_or_older" id="older">
<label for="older">13 or older</label>
</fieldset>
<fieldset class="profile">
<legend><span class="number">2</span>Your profile</legend>
<label for="bio">Biography:</label>
<textarea name="bio" id="bio"></textarea>
</fieldset>
<fieldset class="job">
<label for="job">Job Role:</label><br>
<select name="job" id="job">
<option value="front-end">Front-End Developer</option>
<option value="back-end">Back-End Developer</option>
<option value="full-stack">Full-Stack Developer</option>
</select>
<p>Interests:</p>
<input type="checkbox" name="interests[]" value="development" id="development">
<label for="development">Development</label><br>
<input type="checkbox" name="interests[]" value="design" id="design">
<label for="design">Design</label><br>
<input type="checkbox" name="interests[]" value="business" id="business">
<label for="business">Business</label>
</fieldset>
<input type="submit" value="Sign Up">
</form>
</body>
</html>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 7-14
CSS for the fieldsets, the legend and the three background colours.
CSS بۆ fieldsetـەکان، legend و سێ ڕەنگی باکگراوند.
- Lineدێڕی 21
A span holds the legend number, so it can be styled.
spanـێک ژمارەی legend هەڵدەگرێت، بۆ ئەوەی بتوانرێت ڕازێنرێتەوە.
- Lineدێڕی 29-32
One radio group: the same
name="age".یەک گرووپی : هەمان
name="age".- Lineدێڕی 42-44
Only "Front-End Developer" is visible in the picture; the other two options are our own examples.
تەنها «Front-End Developer» لە وێنەکەدا دیارە؛ دوو هەڵبژاردەکەی تر نموونەی خۆمانن.
Common mistakesهەڵەکانی باو
| Mistake | Resultئەنجام | Fixچارەسەر |
|---|---|---|
A field has no name nameـی نییە | Its value is never sent. هەرگیز نانێردرێت. | Give every field a clear name.nameـێکی ڕوون بدە هەموو خانەیەک. |
| Curly quotes in attributes خوار لە | Wrong types, wrong names, GET instead of POST.جۆری نادروست، ناوی نادروست، GET لەبری POST. | Straight quotes only.تەنها ڕاست. |
| Radio buttons with different names بە ناوی جیاواز | The user can choose all of them.بەکارهێنەر دەتوانێت هەموویان هەڵبژێرێت. | One shared name per group.یەک nameـی هاوبەش بۆ هەر گرووپێک. |
for does not match the idfor لەگەڵ id یەک ناگرێتەوە | Clicking the label does nothing.کرتەکردن لە هیچ ناکات. | Use exactly the same text in for and id.ڕێک هەمان دەق لە for و idدا بەکاربهێنە. |
| Login form with GET بە GET | The password appears in the URL and history. لە و مێژوودا دەردەکەوێت. | method="post" |
Trusting required, min, maxمتمانەکردن بە required، min، max | Anyone can bypass them.هەر کەسێک دەتوانێت تێیان پەڕێنێت. | Check again in PHP.لە PHPـدا دووبارە بپشکنە. |
type="datetime"type="datetime" | A plain text box. ئاسایی. | type="datetime-local" |
More exercisesڕاهێنانی زیاتر
This form was copied from slides and has five problems. Find them and write a correct version.
ئەم لە سلایدەوە کۆپی کراوە و پێنج کێشەی هەیە. بیاندۆزەوە و وەشانێکی دروست بنووسە.
<form action=”save.php” method=”post”>
<label for="user">Name:</label>
<input type="text" name="username" id="name">
<label>Password:</label>
<input type="password">
Year:
<input type="radio" name="year1" value="1"> 1
<input type="radio" name="year2" value="2"> 2
<input type="submit" value="Save">
</form>Show answerوەڵامەکە پیشان بدە
- Curly quotes in
actionandmethod(the method falls back to GET). <label for="user">does not matchid="name".- The password label has no
for, and the password field has nonameand noid, so it is never sent. - The radio buttons have different names (
year1,year2), so both can be chosen. - The numbers 1 and 2 next to the radios are not labels.
- خوار لە
actionوmethodدا (method دەگەڕێتەوە بۆ GET). <label for="user">لەگەڵid="name"یەک ناگرێتەوە.-
forـی نییە وnameوidـی نییە، بۆیە هەرگیز نانێردرێت. - ناوی جیاوازیان هەیە (
year1،year2)، بۆیە هەردووکیان دەتوانرێن هەڵبژێردرێن. - ژمارەکانی 1 و 2 لە تەنیشت نین.
<form action="save.php" method="post">
<label for="name">Name:</label>
<input type="text" name="username" id="name">
<label for="password">Password:</label>
<input type="password" name="password" id="password">
<p>Year:</p>
<input type="radio" name="year" value="1" id="year1">
<label for="year1">1</label>
<input type="radio" name="year" value="2" id="year2">
<label for="year2">2</label>
<input type="submit" value="Save">
</form>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<form action="save.php" method="post">
<label for="name">Name:</label>
<input type="text" name="username" id="name">
<label for="password">Password:</label>
<input type="password" name="password" id="password">
<p>Year:</p>
<input type="radio" name="year" value="1" id="year1">
<label for="year1">1</label>
<input type="radio" name="year" value="2" id="year2">
<label for="year2">2</label>
<input type="submit" value="Save">
</form>A visitor types web programming in the search box of this form, chooses Books and clicks Search. Write the address the browser opens.
سەردانیکەرێک web programming لە خانەی گەڕانی ئەم دەنووسێت، Books هەڵدەبژێرێت و کرتە لە Search دەکات. ئەو ناونیشانە بنووسە کە دەیکاتەوە.
<form action="search.php" method="get">
<input type="search" name="q">
<select name="type">
<option value="all">All</option>
<option value="books">Books</option>
</select>
<input type="submit" value="Search">
</form>Hintئاماژە
GET puts name=value pairs after ?, joined with &. A space becomes +. The submit button has no name.
GET جووتەکانی name=value دوای ? دادەنێت، بە & پێکەوە. دەبێتە +. nameـی نییە.
Show answerوەڵامەکە پیشان بدە
search.php?q=web+programming&type=books (on the same server as the form, for example http://localhost/search.php?q=web+programming&type=books). The value of the option, books, is sent, not its text.
search.php?q=web+programming&type=books (لەسەر هەمان ، بۆ نموونە http://localhost/search.php?q=web+programming&type=books). هەڵبژاردەکە، books، دەنێردرێت، نەک دەقەکەی.
Rebuild the lecture's "HTML Forms Example" page. Box 1, Academic information: a Degree drop-down list (Bachelor of Arts, Bachelor of Science, Master of Business Administration, chosen in advance), a Student ID field and a "Classes attended" list where several classes can be chosen (Geography, Mathematics, English). Box 2, Personal details: first name, last name, gender (Male/Female) and e-mail. Below: a read-only terms box, then Send Form and Clear Form buttons. Also send the hidden value subject=Class.
لاپەڕەی «HTML Forms Example»ـی وانەکە دووبارە دروست بکەرەوە. سندووقی ١، Academic information: بۆ Degree (Bachelor of Arts، Bachelor of Science، Master of Business Administration کە پێشتر هەڵبژێردراوە)، خانەیەک بۆ Student ID و لیستێکی «Classes attended» کە چەند وانەیەک تێیدا هەڵدەبژێردرێت (Geography، Mathematics، English). سندووقی ٢، Personal details: ناوی یەکەم، ناوی کۆتایی، ڕەگەز (Male/Female) و . لە خوارەوە: سندووقێکی مەرجەکان کە ، پاشان دوگمەکانی Send Form و Clear Form. هەروەها شاراوەی subject=Class بنێرە.
Hintئاماژە
Use <fieldset> and <legend> for the two boxes, multiple and classes[] for the list, readonly for the terms and type="reset" for Clear Form.
بۆ دوو سندووقەکە <fieldset> و <legend>، بۆ لیستەکە multiple و classes[]، بۆ مەرجەکان readonly و بۆ Clear Form type="reset" بەکار بهێنە.
Show answerوەڵامەکە پیشان بدە
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Forms Example</title>
</head>
<body>
<form action="enrol.php" method="post">
<input type="hidden" name="subject" value="Class">
<fieldset>
<legend>Academic information</legend>
<p><label for="degree">Degree</label>
<select name="degree" id="degree">
<option value="BA">Bachelor of Arts</option>
<option value="BS">Bachelor of Science</option>
<option value="MBA" selected>Master of Business Administration</option>
</select></p>
<p><label for="studentid">Student ID</label>
<input type="text" name="studentid" id="studentid"></p>
<p><label for="classes">Classes attended</label>
<select name="classes[]" id="classes" multiple size="3">
<option>Geography</option>
<option>Mathematics</option>
<option>English</option>
</select></p>
</fieldset>
<fieldset>
<legend>Personal details</legend>
<p><label for="fname">First name</label>
<input type="text" name="fname" id="fname"></p>
<p><label for="lname">Last name</label>
<input type="text" name="lname" id="lname"></p>
<p>Gender:
<input type="radio" name="gender" id="gm" value="m"> <label for="gm">Male</label>
<input type="radio" name="gender" id="gf" value="f"> <label for="gf">Female</label></p>
<p><label for="email">Email</label>
<input type="email" name="email" id="email"></p>
</fieldset>
<p><textarea name="terms" rows="4" cols="30" readonly>TERMS AND CONDITIONS...</textarea></p>
<p>
<input type="submit" value="Send Form">
<input type="reset" value="Clear Form">
</p>
</form>
</body>
</html>Two fixes to the lecture's code: its Student ID is a password field whose label points to an id that does not exist, and it writes "Bachelor of Art". Here the Student ID is a normal text field with a matching id, and the degree is Bachelor of Arts.
دوو ڕاستکردنەوە لە کۆدی وانەکەدا: Student IDـەکەی و ئاماژە بە idـێک دەکات کە بوونی نییە و «Bachelor of Art» دەنووسێت. لێرەدا Student ID ئاساییە بە idـی هاوتا و بڕوانامەکە Bachelor of Artsـە.
More exercisesڕاهێنانی زیاتر
Find the bugs: a registration pageهەڵەکان بدۆزەوە: لاپەڕەیەکی تۆمارکردن
A practical homework asked for a page with a student registration form and, under it, a table of all records. This solution looks right in the browser, but it has many bugs. Some would stop the form from working with PHP.
ئەرکێکی ماڵەوەی پراکتیکی داوای لاپەڕەیەکی دەکرد کە تۆمارکردنی خوێندکار و لە ژێریدا هەموو تێدا بێت. ئەم چارەسەرە لە دروست دەردەکەوێت، بەڵام زۆر هەڵەی تێدایە. هەندێکیان ڕێگە نادەن لەگەڵ PHP کار بکات.
<html>
<head>
<title>Registration</title>
</head>
<body>
<h1>Welcome To Registration Form</h1>
<h2>Student Registration</h2>
<b><u>Required Fields *</u></b>
<br><br><br><br><br>
<form>
<label>First Name:</label>
<input type="text" placeholder="First Name"><br><br>
<label>Middle Name:</label>
<input type="text" placeholder="Middle Name"><br><br>
<label>Last Name:</label>
<input type="text" placeholder="Last Name"><br><br>
<label>First Name:</label>
<input type="text" placeholder="First Name"><br><br>
<label>Department:
<select>
<option>IT</option>
<option>Bank</option>
<option>Businees</option>
<option>Accounting</option>
</select>
</label><br><br>
<input type="submit" value="Register...">
</form>
<h1>All Recors...</h1>
<table border="1" style="border: 1px solid black; border-collapse: collapse;">
<thead>
<tr><th>#</th><th>First Name</th><th>Middle Name</th><th>Last Name</th><th>Department</th></tr>
<tr><td>1</td><td>Aram</td><td>Kamal</td><td>Aziz</td><td>IT</td></tr>
<tr><td>2</td><td>Shilan</td><td>Omar</td><td>Salih</td><td>Bank</td></tr>
</thead>
</table>
</body>
</html>Find at least eight problems in this page, then write a corrected version.
لانیکەم هەشت کێشە لەم لاپەڕەیەدا بدۆزەوە، پاشان وەشانێکی ڕاستکراوە بنووسە.
Hintئاماژە
Look at the top of the file, at every <input>, at the labels, at the table sections and at the spelling.
سەیری سەرەتای فایلەکە، هەموو <input>ێک، ، بەشەکانی و ڕێنووسەکە بکە.
Show answerوەڵامەکە پیشان بدە
- No
<!DOCTYPE html>, nolangand no<meta charset="UTF-8">. - The form has no
actionand nomethod, so it is sent back to the same page with GET. - No
<input>and no<select>has aname, so nothing would reach PHP. - The labels are not linked: there are no
forandidpairs (only Department works, because its label wraps the list). - "First Name" appears twice: it was copied from the assignment picture.
- The data rows are inside
<thead>; they belong in<tbody>. border="1"is obsolete and repeats the CSS border next to it.- Five
<br>tags and<br><br>after each field are used for spacing; spacing is a job for CSS (margin). - Typos: "Businees" (Business) and "Recors" (Records). The second
<h1>would also be better as<h2>.
<!DOCTYPE html>،langو<meta charset="UTF-8">نین.-
actionوmethodـی نییە، بۆیە بە GET بۆ هەمان لاپەڕە دەنێردرێتەوە. - هیچ
<input>و<select>ێکnameـی نییە، بۆیە هیچ شتێک ناگاتە PHP. - نەبەستراونەتەوە: هیچ جووتێکی
forوidنییە (تەنها Department کار دەکات، چونکە لیستەکە لە خۆ دەگرێت). - «First Name» دوو جار هاتووە: لە وێنەی ئەرکەکەوە کۆپی کراوە.
- لەناو
<thead>دان؛ شوێنیان<tbody>ـە. border="1"کۆن و لابراوە و هەمان کاری بۆردەری CSSـی تەنیشتی دووبارە دەکاتەوە.- پێنج
<br>و<br><br>دوای هەر خانەیەک بۆ بۆشایی بەکارهاتوون؛ بۆشایی کاری CSSـە (margin). - هەڵەی ڕێنووس: «Businees» (Business) و «Recors» (Records). باشترە
<h1>ـی دووەمیش ببێتە<h2>.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Registration</title>
<style>
form p { margin: 0 0 12px; }
table, th, td { border: 1px solid black; border-collapse: collapse; }
th, td { padding: 4px 8px; }
</style>
</head>
<body>
<h1>Welcome to the Registration Form</h1>
<h2>Student Registration</h2>
<p><strong>Required fields *</strong></p>
<form action="register.php" method="post">
<p><label for="first">First name *</label>
<input type="text" name="first_name" id="first" placeholder="First name" required></p>
<p><label for="middle">Middle name</label>
<input type="text" name="middle_name" id="middle" placeholder="Middle name"></p>
<p><label for="last">Last name *</label>
<input type="text" name="last_name" id="last" placeholder="Last name" required></p>
<p><label for="department">Department</label>
<select name="department" id="department">
<option>IT</option>
<option>Bank</option>
<option>Business</option>
<option>Accounting</option>
</select></p>
<p><input type="submit" value="Register"></p>
</form>
<h2>All records</h2>
<table>
<thead>
<tr><th>#</th><th>First name</th><th>Middle name</th><th>Last name</th><th>Department</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>Aram</td><td>Kamal</td><td>Aziz</td><td>IT</td></tr>
<tr><td>2</td><td>Shilan</td><td>Omar</td><td>Salih</td><td>Bank</td></tr>
</tbody>
</table>
</body>
</html>Summary and reviewکورتە و پێداچوونەوە
- A form collects user input.
actionsays where it goes,methodsays how (GET in the URL, POST inside the request). - Every field that should be sent needs a
name; the browser sendsname=valuepairs. - Labels (
for=id) make forms easier to use. - Controls: text, password, radio (one choice per name), checkbox (many), select/option, textarea, submit.
- HTML5 types (email, number, date, color…) and attributes (required, min, max, placeholder, autofocus) help the user, but PHP must still validate.
- Use straight quotes everywhere;
datetimeis obsolete.
- کۆ دەکاتەوە.
actionدەڵێت بۆ کوێ دەچێت،methodدەڵێت چۆن (GET لەناو ، POST لەناو ). - هەموو کە دەبێت بنێردرێت پێویستی بە
nameهەیە؛ جووتەکانیname=valueدەنێرێت. - (
for=id) بەکارهێنانی ئاسانتر دەکەن. - : text، password، radio (یەک هەڵبژاردە بۆ هەر ناوێک)، checkbox (زۆر)، select/option، textarea، submit.
- جۆرەکانی HTML5 (email، number، date، color…) و (required، min، max، placeholder، autofocus) یارمەتیی بەکارهێنەر دەدەن، بەڵام PHP هێشتا دەبێت بپشکنێت.
- لە هەموو شوێنێک ڕاست بەکاربهێنە؛
datetime.
What do the action and method attributes do?خەسڵەتەکانی action و method چی دەکەن؟
action gives the address of the page that receives the data when the form is submitted. method chooses GET (data in the URL) or POST (data inside the request); the default is GET.
action ناونیشانی ئەو دەدات کە کاتی ناردنی دراوەکان وەردەگرێت. method GET (دراوە لەناو ) یان POST (دراوە لەناو ) هەڵدەبژێرێت؛ بە شێوەی بنەڕەتی GETـە.
What is the difference between radio buttons and checkboxes?جیاوازیی نێوان دوگمەکانی ڕادیۆ و چێکبۆکسەکان چییە؟
Radio buttons with the same name allow exactly one choice. Checkboxes allow any number of choices, including none.
بە هەمان ناو تەنها یەک هەڵبژاردە ڕێگە دەدەن. هەر ژمارەیەک هەڵبژاردە ڕێگە دەدەن، تەنانەت هیچیش.
What is sent from <option>Erbil</option> when it is chosen in <select name="cities">?کاتێک <option>Erbil</option> لە <select name="cities">دا هەڵدەبژێردرێت، چی دەنێردرێت؟
cities=Erbil: without a value attribute, the option's text is sent.
cities=Erbil: بەبێ value، دەقی هەڵبژاردەکە دەنێردرێت.
Name the four important HTML5 attributes from the lecture and what they do.چوار خەسڵەتە گرنگەکەی HTML5 لە وانەکەدا ناو بهێنە و بڵێ چی دەکەن.
autofocus: focus this field when the page loads. min/max: smallest and largest allowed value. placeholder: a grey hint. required: the field must be filled in.
autofocus: لە کاتی کردنەوەی دەخاتە ئەم خانەیە. min/max: بچووکترین و گەورەترین ڕێگەپێدراو. placeholder: ڕێنماییەکی خۆڵەمێشی. required: خانەکە دەبێت پڕ بکرێتەوە.
Why did the HTML5 examples on the slide all show plain text boxes?بۆچی نموونەکانی HTML5 لە سلایدەکەدا هەموویان خانەکانی دەقی ئاسایی پیشان دەدەن؟
Because of the curly quotes: the browser reads an invalid type and falls back to a text box.
بەهۆی خوارەوە: typeـێکی نادروست دەخوێنێتەوە و دەگەڕێتەوە بۆ .
What are fieldset and legend for?fieldset و legend بۆ چین؟
<fieldset> groups related controls inside a border; <legend> gives that group a title.
<fieldset> پەیوەندیدار لەناو هێڵێکدا کۆ دەکاتەوە؛ <legend> ناونیشانێک دەداتە ئەو گرووپە.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
Covers every part of an HTML form: action and method, labels, input types, placeholders, validation, checkboxes, radio buttons, select lists and text areas.
هەموو بەشەکانی ڕوون دەکاتەوە: و method، ، جۆرەکانی ، ، ، ، ، و .
Whole video: complete overview of HTML forms with chapters
هەموو ڤیدیۆکە: ناساندنێکی تەواوی ، دابەشکراو بە چەند بەشێک.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
CSS Basics: Rules, Three Places and Coloursبنەماکانی CSS: ڕێسا، سێ شوێن و ڕەنگ
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- MDN: The form element <form>
- MDN: The input element <input> (all types)
- MDN: The label element <label>
- MDN: The select element <select>
- MDN: The fieldset element <fieldset>
- MDN: Client-side form validation
- WHATWG HTML Living Standard: Forms
- WHATWG HTML Living Standard: The input element
- PHP Manual: Dealing with Forms
- PHP Manual: htmlspecialchars()
- MDN: <datalist>
- MDN: HTML attribute readonly
- MDN: <input type="hidden">
- HTML Standard: constructing the entry list (disabled controls are skipped)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.