Page:
chap5_forms_and_html_helpers
1
chap5_forms_and_html_helpers
jason-zhu edited this page 2023-10-22 12:15:53 +11:00
Chapter 5: Forms and HTML Helpers
Topic in this chapter: (May not be summarized)
- Understanding forms
- How to make HTML helpers work for you
- Editing and inputting helpers
- Displaying and rendering helpers
HTML helpers requires coordination between a view and the runtim.
Using Forms
Before understanding HTML helper, first get familiar with HTML form
tag.
The Action and the Method
A form is a container for one or more different input elements, e.g.:
- buttons
- checkboxs
- text inputs, etc.
How form submit user entered information to server:
- through
action
andmethod
attributes of aform
tag action
attribute tell browser where to send information, hence normally contains URL (relative or absolute)method
attribute tell browser useGET
(default) orPOST
requests.- When a user submits a form using an HTTP GET request, the browser takes the input names and values inside the form and puts them in query string.
e.g. HTML form tag transform to URL
<form action="http://www.bing.com/search" method="get">
<input name="q" type="text" />
<input type="submit" value="Search!">
</form>
to http://www.bing.com/search?q=love
Details of HTML form is available in w3schools
To GET or To POST
Difference btw GET and POST:
GET
request: browser place input values into query stringPOST
request: browser place input values inside the body of the HTTP request instead.
Web app generally use GET requests for reads and POST requests for writes.