Form builder
Form Modal
<?php
namespace Models\Forms;
class ContactForm extends AbstractForm
{
/**
* createForm method is an required, abstract method used to build form
* @return void
*/
protected function createForm(): void
{
$this->form->add([
"firstname" => [
"type" => "text",
"label" => "First name",
"validate" => [
"length" => [1, 60]
]
],
"lastname" => [
"type" => "text",
"label" => "Last name",
"validate" => [
"length" => [1, 80]
]
],
"email" => [
"type" => "text",
"label" => "Email",
"attr" => [
"type" => "email"
],
"validate" => [
"length" => [1, 160]
]
],
"message" => [
"type" => "textarea",
"label" => "Message",
"validate" => [
"length" => [1, 2000]
]
]
]);
}
}Controller
Form fields:
Create fields
Field config
type (string)
label (string)
description (string)
attr (array)
items (array)
validate (array)
config (multidimensional array)
Breaking down the examples:
1. Create form with array
2. Set values if you want
3. Build the form
4. Read form
5. Validate form
Last updated