FormModule
A high-level form using the same protected preview endpoint.
Contact preview
Java composition
Form form = Form.create()
.withAction("/demos/api/form-preview").withMethod(Form.Method.POST)
.withHxPost("/demos/api/form-preview").withHxTarget("#form-preview").withHxSwap("outerHTML")
.addField("Name", TextInput.create("name").required())
.addField("Email", TextInput.email("email").required())
.addField("Role", Select.create("role").addOption("engineer", "Engineer").addOption("designer", "Designer"))
.withChild(Button.submit("Render preview"))
.withChild(new Div().withId("form-preview").withAttribute("role", "status")
.withInnerText("Your server-rendered result appears here."));
// Application SSR adds one _csrf field and inherited literal hx-headers.
FormModule.create().withTitle("Contact preview").withForm(form);