Skip to content

HTML Form Handling

Sudheer edited this page Mar 11, 2023 · 8 revisions

Set of functions to manage a HTML form that is submitted by the client (typically a browser) Deals with form fields

The form object is acquired in the server code in the following method

local request = platform.get_http_request();
local form = request:parse_req_form();

form.empty(form)

Examines if the given HTML form is empty

Parameters:
    form: userdata, HTML form handle
Return:
    flg: boolean, true if empty, false otherwise

ERROR:
    Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall

form.begin_iteration(form)

Begins iterating through the list of form fiels

Parameters:
    form: userdata, HTML form handle
Return:
    name: string, field name, nil if there are no fields
    value: string, nil if there are no fields

ERROR:
    Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall

form.next_iteration(form)

Gets the next form field

Parameters:
    form: userdata, HTML form handle
Return:
    name: string, field name, nil if there are no more fields
    value: string, nil if there are no more fields

ERROR:
    Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall

form.get_form_field(form, field_name)

Retrieves the value of a form field

Parameters:
    form: userdata, HTML form handle
    field_name: string, form field name
Return:
    value: string

ERROR:
    Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall

Clone this wiki locally