Malloy
|
#include <form.hpp>
Public Types | |
enum class | encoding { url , multipart , plain } |
Public Member Functions | |
form (http::method method, std::string action, encoding enc) | |
virtual | ~form ()=default |
http::method | method () const noexcept |
std::string_view | action () const noexcept |
encoding | get_encoding () const noexcept |
std::string_view | encoding_to_string () const |
std::vector< form_field > | fields () const noexcept |
bool | add_field (form_field &&field) |
bool | has_field (std::string_view field_name) const |
void | populate (const form_data &data) |
void | clear_values () |
Static Public Member Functions | |
static std::string_view | encoding_to_string (encoding enc) |
static std::optional< encoding > | encoding_from_string (std::string_view str) |
static std::optional< form_data > | parse (const malloy::http::request<> &req) |
Class for handling HTML forms.
This class supports all three encoding types supported by HTML5:
|
strong |
Encoding type.
form::form | ( | http::method | method, |
std::string | action, | ||
encoding | enc | ||
) |
Constructor.
method | The HTTP method. |
action | the Action (eg. target link). |
enc | The encoding type. |
|
virtualdefault |
Destructor.
|
inlinenoexcept |
Get the action string.
bool form::add_field | ( | form_field && | field | ) |
Adds a field to the form.
field | The field. |
void form::clear_values | ( | ) |
Clears the pre-population values of all fields.
|
static |
Returns the econding type corresponding to the provided MIME type/
str | The MIME type (eg. "application/x-www-form-urlencoded"). |
|
inline |
Returns the MIME type corresponding to the encoding type.
|
static |
Returns the MIME type corresponding to the encoding type.
|
inlinenoexcept |
Get the form fields.
|
inlinenoexcept |
Get encoding type.
bool form::has_field | ( | std::string_view | field_name | ) | const |
Checks whether a field with a specific name already exists.
field_name | The field name. |
|
inlinenoexcept |
Get the method.
|
static |
Parse a request matching this form.
req | The request. |
void form::populate | ( | const form_data & | data | ) |
This will update each field's value member with the content member of the parsed data;
This function is useful to call if serving the same form back to the user after parsing to pre-populate form fields so the user doesn't have to re-enter everything.
data | The data. |