| Crates.io | reinhardt-forms |
| lib.rs | reinhardt-forms |
| version | 0.1.0-alpha.1 |
| created_at | 2026-01-23 04:47:39.169535+00 |
| updated_at | 2026-01-23 04:47:39.169535+00 |
| description | Form handling and validation |
| homepage | |
| repository | https://github.com/kent8192/reinhardt-rs |
| max_upload_size | |
| id | 2063460 |
| size | 385,742 |
Django-inspired form handling and validation for Rust
reinhardt-forms provides a comprehensive form system for form handling and validation. Inspired by Django's forms framework, it offers both automatic form generation from models and manual form definitions with extensive validation capabilities.
This crate is designed to be WASM-compatible, providing a pure form processing layer without HTML generation or platform-specific features. For HTML rendering, see reinhardt-pages.
Add reinhardt to your Cargo.toml:
[dependencies]
reinhardt = { version = "0.1.0-alpha.1", features = ["forms"] }
# Or use a preset:
# reinhardt = { version = "0.1.0-alpha.1", features = ["standard"] } # Recommended
# reinhardt = { version = "0.1.0-alpha.1", features = ["full"] } # All features
# Enable the form! macro:
# reinhardt = { version = "0.1.0-alpha.1", features = ["forms", "form-macros"] }
Then import form features:
use reinhardt::forms::{Form, Field, CharField, IntegerField};
Note: Form features are included in the standard and full feature presets.
Form Base (Form): Complete form data structure with binding and validation
BoundField: Field bound to form data
WASM Compatibility (wasm_compat): WASM-compatible form metadata
FormMetadata: Serializable form state for client-side processingFieldMetadata: Field information for client-side renderingValidationRule: Client-side validation rule definitionsBasic Fields:
CharField: Text input with min/max length, stripping, null character validationIntegerField: Integer input with min/max value constraints, string parsingBooleanField: Boolean/checkbox input with flexible type coercionEmailField: Email validation with regex, length constraintsAdvanced Fields:
FloatField: Floating-point number validation with min/max constraintsDecimalField: Precise decimal number handling with scale and precisionDateField: Date input with multiple format support and locale handlingTimeField: Time input with format parsingDateTimeField: Combined date and time validationURLField: URL validation with scheme and max length checksJSONField: JSON data validation and parsingFileField: File upload handling with size validationImageField: Image file validation with dimension checksChoiceField: Selection from predefined choicesMultipleChoiceField: Multiple selection supportRegexField: Pattern-based validation with custom regexSlugField: URL slug validationGenericIPAddressField: IPv4/IPv6 address validationUUIDField: UUID format validationDurationField: Time duration parsingComboField: Multiple field validation combinationMultiValueField: Composite field handling (base for split fields)SplitDateTimeField: Separate date and time inputsModel-Related Fields:
ModelChoiceField: Foreign key selection with queryset supportModelMultipleChoiceField: Many-to-many selectionModelForm (ModelForm<T>): Automatic form generation from models
FormModel trait for model integrationModelFormBuilder: Fluent API for ModelForm configuration
ModelFormConfig: Configuration structure for ModelForm behavior
FormSet: Managing multiple forms together
ModelFormSet: Formset for model instances
ModelFormSetConfigModelFormSetBuilderForm Wizard (FormWizard): Multi-step form flow
WizardStep)form! Macro (with macros feature): Declarative form definition
Field Validation: Individual field cleaning and validation
Form Validation: Multi-field validation
add_clean_function)add_field_clean_function)Error Handling: Comprehensive error reporting
FieldError types (Required, Invalid, Validation)FormError types (Field, Validation)Security and UI features have been moved to dedicated crates:
reinhardt-middleware::csrfreinhardt-middleware::rate_limitreinhardt-middleware::honeypotreinhardt-middleware::xssreinhardt-pages for form renderinguse reinhardt::forms::{Form, CharField, IntegerField, FormField};
use std::collections::HashMap;
use serde_json::json;
let mut form = Form::new();
form.add_field(Box::new(CharField::new("name".to_string())));
form.add_field(Box::new(IntegerField::new("age".to_string())));
let mut data = HashMap::new();
data.insert("name".to_string(), json!("John"));
data.insert("age".to_string(), json!(30));
form.bind(data);
assert!(form.is_valid());
use reinhardt::forms::form;
use std::collections::HashMap;
use serde_json::json;
let mut form = form! {
fields: {
username: CharField {
required,
max_length: 150,
},
password: CharField {
required,
widget: PasswordInput,
},
},
validators: {
username: [
|v: &serde_json::Value| v.as_str().map_or(false, |s| s.len() >= 3)
=> "Username must be at least 3 characters",
],
},
client_validators: {
password: [
"value.length >= 8" => "Password must be at least 8 characters",
],
},
};
let mut data = HashMap::new();
data.insert("username".to_string(), json!("john"));
data.insert("password".to_string(), json!("secret123"));
form.bind(data);
assert!(form.is_valid());
use reinhardt::forms::{ModelForm, ModelFormBuilder};
let form = ModelFormBuilder::<User>::new()
.include_fields(vec!["name", "email"])
.build();
use reinhardt::forms::{Form, FormError};
let mut form = Form::new();
form.add_clean_function(|data| {
if data.get("password") != data.get("confirm_password") {
Err(FormError::Validation("Passwords do not match".to_string()))
} else {
Ok(())
}
});
This crate follows Django's forms philosophy:
Licensed under either of Apache License, Version 2.0 or MIT license at your option.