The form controls of the Add Term page
The Add Term page has a title in its own div and a form below it. The form has four controls for the four things we store, and a button. A text box takes the term and another takes its translation. A text area takes the definition, which is longer. A file box lets the visitor choose the picture. The submit button sends everything to add_term.php, the same page, which will handle it in Week 14. Every control has a name, and the name matters, because PHP finds the value by that name: $_POST['term'] will hold what was typed in the box named term. The book’s names (txt_term, TextArea1, File1, Submit1) are not clear, so we use term, trans, defe, picture and add_btn. Keep the names exactly the same in the form and in the PHP. The PHP that includes the header goes at the top of the page, and the PHP that reacts to the button goes below the form.
| Control | name | What PHP gets |
|---|---|---|
| text box | term | $_POST['term']: the typed term |
| text box | trans | $_POST['trans']: its translation |
| text area | defe | $_POST['defe']: the definition |
| file box | picture | $_FILES['picture']: the chosen file |
| submit button | add_btn | $_POST['add_btn']: set when pressed |
1<div><h2>Add a term</h2></div> 2<form method="post" action="add_term.php" enctype="multipart/form-data"> 3<p>Term: <input name="term" type="text"></p> 4<p>Translation: <input name="trans" type="text"></p> 5<p>Definition:<br><textarea name="defe" rows="4" cols="40"></textarea></p> 6<p>Picture: <input name="picture" type="file"></p> 7<p><input name="add_btn" type="submit" value="Add"></p> 8</form>
The page shows the heading Add a term; then a text box for the term, a text box for the translation, a larger box for the definition, a file chooser for the picture, and a button labelled Add.
| Form says | PHP asks for | Works? |
|---|---|---|
| name="term" | $_POST['term'] | yes |
| name="term" | $_POST['Term'] | no: different letter case |
| name="defe" | $_POST['definition'] | no: different name |
On paper design the form for adding a book to a library (title, writer, short summary, a cover picture and a button). Write the HTML for each control with a clear name, then a table with the control, its name and what PHP would read.