Form

Forms are accessed through the context using ctx.form() method. Forms submitted in POST request can be url encoded or multipart. Different form parsing techniques are used by udho::urlencoded_form and udho::multipart_form.

API

udho::form

template<typename RequestT>
struct udho::form_

unified form accessor that can extract field from both urlencoded as well as multipart forms.

Public Functions

void parse_urlencoded()

parse the beast request body as urlencoded form data

void parse_multipart()

parse the beast request body as multipart form data

bool is_urlencoded() const

check whether the submitted form is urlencoded

bool is_multipart() const

check whether the submitted form is multipart

const urlencoded_form<std::string::const_iterator> &urlencoded() const

return the urlencoded specific form accessor

const multipart_form<std::string::const_iterator> &multipart() const

return the multipart specific form accessor

bool parsed() const

returns true once the form is parsed

bool has(const std::string &name) const

checks whether the form contains any field with matching name

Parameters
  • name: name of the form field

template<typename V>
V field(const std::string &name) const

returns a form field object for a given field

fields_map_type::size_type count() const

returns number of fields in the form

udho::urlencoded_form

template<typename Iterator>
struct udho::urlencoded_form

Form accessor for urlencoded forms

Public Functions

std::size_t count() const

number of fields in the form

bool has(const std::string name) const

checks whether there exists any field with the name provided

template<typename T>
const T field(const std::string &name) const

returns the value of the field with the name provided lexically casted to type T

udho::multipart_form

template<typename Iterator>
struct udho::multipart_form

Form accessor for multipart forms

Public Functions

std::size_t count() const

number of fields in the form

bool has(const std::string name) const

checks whether the form has any field with the given name

const form_part &part(const std::string &name) const

returns the part associated with the given name

template<typename T>
const T field(const std::string &name) const

returns the value of the field lexically casted with the desired type

form.field<int>("age");

struct form_part

A part in the multipart form data

Public Functions

const bounded_string_type &header(const std::string &key) const

returns the value associated with the key in the header of the part

header("Content-Disposition").copied<std::string>();

bounded_string_type header(const std::string &key, const std::string &sub) const

returns the value associated with the key and sub key in the header of the part

header("Content-Disposition", "name").copied<std::string>();

bounded_string_type name() const

name of the part

name().copied<std::string>();

bounded_string_type filename() const

filename of the part

name().copied<std::string>();

const bounded_string_type &body() const

body of the part returned as a pair of string iterators

body().copied<std::string>();

std::string str() const

returns the body of the part as string

template<typename T>
T value() const

lexically convert the contents of the body to the requested type