set_form_input
Sets the value of specified form fields from HTTP POST and PUT requests in NGINX.
Description
The set_form_input directive is part of the NGINX form input module, which processes application/x-www-form-urlencoded content type in HTTP requests. This directive allows users to capture values from form fields sent in the request body directly into variables for further processing. It can be used with up to two arguments; the first is the variable to populate, and the optional second argument is the specific form field name to extract. If no field name is specified, it will read the entire body content into the mentioned variable.
This directive can be configured in various contexts including http, server, and location. Upon invocation, NGINX will parse the request body when a matching request is received, assuming the request method is POST or PUT. The set_form_input_multi variant allows for capturing multiple values for a single field, storing them as an array-like structure, which can further be manipulated by other directives such as array_join. Careful management of request body size with directives like client_max_body_size and client_body_buffer_size is necessary to avoid truncation of input data.
In conclusion, set_form_input not only helps in populating variables with request data but also enables developers to create dynamic and interactive web applications efficiently. The interaction of this directive with other configuration directives can significantly enhance the capability of NGINX as a web server in handling dynamic forms and user inputs.
Config Example
location /submit {
client_max_body_size 100k;
client_body_buffer_size 100k;
set_form_input $name;
set_form_input $email email;
}Make sure to set appropriate limits on client_max_body_size and client_body_buffer_size to avoid dropped requests.
Always define the variable to capture data properly; failing to do so may result in empty values.
Using it in the wrong context (like if blocks) can lead to unexpected behavior. Use in location or higher contexts only.