form_fields 0.1.0

Helper crate for working with HTML forms.
Documentation

Form Fields

Helper crate for working with HTML forms in axum.

Simplifies the parsing and validating user input for creating new and editing existing data in your application.

Examples

In The Examples folder folder, you can find a few basic examples.

Basic usage

Derive from "FromForm" on a struct with the data you allow the user to submit.

#[derive(Debug, FromForm)]
struct Test {
    #[text_field(display_name = "Required Text", max_length = 50)]
    text: String,
}

This will generate a Form-Spec, which can be retrieved in your axum-handlers.

async fn simple(method: Method, FromForm(mut form): FromForm<Test>) -> Response<Body> {
    if method == Method::POST {
        let inner = form.inner().unwrap();
        println!("Form submitted: text: {}", inner.text);
    }
    html! {
        h1 { "Simple Form Example" }
        form method="POST" {
            (form.text)
            input type="submit";
        }
    }
    .into_response()
}

Currently, only maud is supported, but all data is exposed so rendering the inputs in any other markup generator or even altering the format is possible.

Goals for stable release

  • documentation
  • better naming (help needed)
    • descriptor
  • feature segregation
    • multer & form_urlencoded
    • axum
    • renderers
    • chrono
  • file handling
    • loaded fully
    • async user handled
  • HTML renderers
    • maud
  • clean up macro code