Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

HTML Form

Also HTML Forms

An HTML form groups input fields so that, on a user action such as clicking a submit button, the browser itself (without JavaScript) sends their values as name=value parameters to the server and loads the returned page.

Formula#

<form method="GET" action="/search">
  <input type="text" name="query"/>
  <input type="submit" value="Search"/>
</form>

Request line produced for input vv on a page http://<host>:<port>/<page>:

GET /<action or page>?<name>=<URL-encoded v> HTTP/1.1

Properties#

  • Default method: GET (if method is omitted). GET submission: input values are appended as query parameters to the URL, e.g. /search?query=example. POST submission: values are sent in the request body instead of the URL.
  • The name attribute of each <input> becomes the query parameter key; inputs without name are not sent.
  • The action attribute specifies the target URL. If omitted, the form submits to the current page URL: <form action="prefix"> sends the request to prefix?abc=xyz.
  • <input type="submit"> or <button type="submit"> triggers submission; the submit input is shown as a button labelled with its value.
  • The values are URL-encoded: a space becomes +, ä becomes %C3%A4. The server must decode them.

Template variables#

A SERP (search engine result page) should be the original page, with the input field showing the query and augmented by the results. The HTML file contains template variables that the server substitutes before sending the page (HTTP Server):

<form>
  <input type="text" value="%QUERY%" name="query"/>
  <input type="submit" value="Search"/>
</form>
%RESULT%

%QUERY% is replaced by the query, %RESULT% by the result (e.g. the fuzzy prefix matches). Substituting raw user input here is a code-injection risk.

Contrast with JavaScript#

AspectHTML FormsJavaScript (fetch / AJAX)
Triggerform submit (browser-native)programmatic (event handler)
Page reloadyes (full page reload)no (asynchronous, partial update)
Responsebrowser renders new pagehandled in callback / .then()
Flexibilitylimited to GET/POSTfull control over request
Course usestatic app (Sheet 9)dynamic app (Sheet 10)

Example#

Sources#

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only