Form

A server-side form wrapper that handles form-group layout, labels with required-field indicators, hint text, automatic CSRF tokens, and an auto-generated client-side Validator — all from a single fluent builder. The Form component is purely PHP; fields with required in their rules automatically display a red asterisk.

Usage pattern: build the form chain, call ->submit() to configure the submit button (returns a Button for fluent chaining), then echo $form to render the complete HTML.

Auto-validating Form

Pass rules as the third argument to ->field(). The Form generates a Validator automatically, deriving error messages from the label text. Override with the optional fourth argument. CSRF token injected by default on POST.

Be as specific as you can.
Fill in the form and click Send Message...
PHP

Cancel & Reset Buttons

->cancel($text, $href, $icon) adds a secondary action button rendered as an anchor link (when $href is given) or a history.back() button when no href is supplied. ->reset($text, $icon) adds a type="reset" button that clears all fields to their initial DOM values. Both methods return the Form for chaining. Action buttons render in the order: submit → cancel → reset.

Cancel
PHP

Reset Button

Use ->reset() on filter or data-entry forms where users may want to clear all inputs. No JavaScript needed — the browser handles it via type="reset".

PHP

All Three Action Buttons

Submit, cancel, and reset can all be combined. They render in one form-actions div in the order: submit → cancel → reset.

Discard
PHP

Model Binding

Pass an associative array or object to ->model() to pre-populate field values. Keys are matched to each component's name() attribute via value().

Max 200 characters.
Cancel
Edit the fields above and click Save Changes...
PHP

Layouts

->layout('horizontal') places labels and fields side-by-side. ->layout('inline') flows all fields into one row — useful for filter bars. Default is vertical.

Horizontal

PHP

No Auto-Validation

->noValidation() suppresses the auto-generated Validator. Use this when the Form is inside a Wizard (which manages validation per-step), or when you want to manage a separate $m->validator() yourself.

PHP

Hidden Fields & Raw HTML

->hidden() injects a <input type="hidden">. ->html() inserts arbitrary markup — useful for captcha images, card wrappers, or any content that doesn't fit the standard field pattern. Complex multi-section forms can capture their body via ob_start()/ob_get_clean() and pass the result to ->html(), letting the Form manage the outer tag and CSRF.

PHP

PHP PHP Methods (Fluent)

Method / PropertyParametersDescription
$m->form($id)stringCreate a Form. The $id is also used as the form's name attribute.
->action($url)stringForm action URL. Defaults to empty (submits to current page).
->method($method)stringHTTP method: post (default), get, put, delete. PUT/DELETE emit a hidden _method field.
->name($name)stringOverride the form name attribute. Defaults to the ID.
->model($data)array|objectBind an associative array or object to pre-populate field values. Keys are matched to component name() attributes.
->field($component, $label, $rules, $errorMessage, $hint, $wrapperClass)Component, string, array, string, string, stringAdd a field wrapped in a form-group div. $rules drive the auto-Validator; $errorMessage overrides the label-derived default; $hint is small text shown below the field; required fields show a red asterisk.
->hidden($name, $value)string, stringInject a <input type="hidden">.
->html($html)stringInsert raw HTML at the current position in the field list.
->submit($text, $icon)string, stringAdd a submit button. Returns a Button instance for further fluent configuration (e.g. ->primary()). Echo the Form variable to render full HTML — not the Button return value.
->cancel($text, $href, $icon)string, string, stringAdd a cancel action. With $href: renders as <a href="…">. Without: onclick="history.back()". Defaults: text Cancel, icon fa-times. Returns self.
->reset($text, $icon)string, stringAdd a type="reset" button. Defaults: text Reset, icon fa-undo. Returns self.
->layout($layout)stringForm layout: vertical (default), horizontal, inline.
->ajax()Set data-m-ajax="true" on the form element.
->noValidation()Suppress the auto-generated client-side Validator.
->noCsrf()Suppress the automatic csrf_token hidden input (injected by default on POST/PUT/DELETE).
->formAttr($name, $value)string, stringAdd an arbitrary attribute to the <form> element (e.g. onsubmit, enctype, autocomplete).