Requests and responses

Send request parameters

Use named controls and ordinary form encoding so the server receives the values it expects.

8 minute lesson

~~~

HTMX follows normal form rules. A form sends its successful named controls:

<form action="/tasks" method="post" hx-post="/tasks">
  <label>
    Task
    <input name="title" required>
  </label>

  <label>
    <input type="checkbox" name="urgent" value="yes">
    Urgent
  </label>

  <button name="intent" value="create">Add task</button>
</form>

The server receives title, receives urgent=yes only when checked, and receives the clicked submit button’s intent. An unnamed control is not submitted. A disabled control is not submitted either.

A GET encodes values in the query string. A POST normally uses the request body according to the form encoding. The server must parse repeated names correctly for multi-select controls and checkbox groups.

Do not infer the payload from what appears on screen. Inspect the Network panel’s query string or form data, then log only safe field names on the server while debugging. Client values remain untrusted even when browser validation ran first.

Lesson completed