@@ -15,7 +15,10 @@ $fields->[FIELD_TYPE]->[ARG1]->[ARG2]->get();
1515** FIELD_TYPE:** Method name from Form\Templates\Fields
1616** ARG:** Chainable arguments like input name, fields attributes, validations and so on.
1717``` php
18- echo $fields->text()->name("email")->attr(["type" => "email"])->get();
18+ echo $fields->text()->name("email")->label("Email address")->attr([
19+ "type" => "email",
20+ "placeholder" => "Input your email..."
21+ ])->get();
1922```
2023## Advance:
2124Use the form compiler for advance consistent form creation and validation. Works really great in frameworks and large applications.
@@ -91,89 +94,89 @@ Pass on custom data for a custom field.
9194#### 1. Create form with array
9295Build a whole form with array as bellow
9396``` php
94- $fields->add("userForm", [
95- "firstname" => [
96- "type" => "text", // Set form type (input text or textarea and so on.)
97- "label" => "First name",
98- "validate" => [
99- "length" => [1, 80]
100- ]
101- ],
102- "lastname" => [
103- "type" => "text",
104- "label" => "Last name",
105- "validate" => [
106- "length" => [1, 120]
107- ]
108- ],
109- "email" => [
110- "type" => "text",
111- "label" => "Email",
112- "description" => "We need you email so that we can contact you.",
113- "attr" => [
114- "type" => "email",
115- "placeholder" => "john.doe@hotmail.com"
116- ],
117- "validate" => [
118- "length" => [1, 120]
119- "!email" => NULL
120- ]
121- ],
122- "nested,item1" => [
123- "type" => "radio",
124- "label" => "Question 1",
125- "validate" => [
126- "length" => [1],
127- ],
128- "items" => [
129- 1 => "Yes",
130- 0 => "No"
131- ],
132- "value" => 1 // Default value
133- ],
134- "nested,item2" => [
135- "type" => "radio",
136- "label" => "Question 2",
137- "validate" => [
138- "length" => [1],
139- ],
140- "items" => [
141- 1 => "Yes",
142- 0 => "No"
143- ],
144- "value" => 1 // Default value
145- ],
146- "message" => [
147- "type" => "textarea",
148- "label" => "Message",
149- "validate" => [
150- "length" => [0, 2000]
151- ]
152- ],
153- "gdpr" => [
154- "type" => "checkbox",
155- //"label" => "GDPR",
156- "validate" => [
157- "length" => [1, 1],
158- "!equal" => [1]
159- ],
160- "items" => [
161- 1 => "I accept that my data will be saved according to GDPR"
162- ]
163- ]
164-
97+ $fields->add([
98+ "firstname" => [
99+ "type" => "text", // Set form type (input text or textarea and so on.)
100+ "label" => "First name",
101+ "validate" => [
102+ "length" => [1, 80]
103+ ]
104+ ],
105+ "lastname" => [
106+ "type" => "text",
107+ "label" => "Last name",
108+ "validate" => [
109+ "length" => [1, 120]
110+ ]
111+ ],
112+ "email" => [
113+ "type" => "text",
114+ "label" => "Email",
115+ "description" => "We need you email so that we can contact you.",
116+ "attr" => [
117+ "type" => "email",
118+ "placeholder" => "john.doe@hotmail.com"
119+ ],
120+ "validate" => [
121+ "length" => [1, 120],
122+ "!email" => NULL
123+ ]
124+ ],
125+ "nested,item1" => [
126+ "type" => "radio",
127+ "label" => "Question 1",
128+ "validate" => [
129+ "length" => [1],
130+ ],
131+ "items" => [
132+ 1 => "Yes",
133+ 0 => "No"
134+ ],
135+ "value" => 1 // Default value
136+ ],
137+ "nested,item2" => [
138+ "type" => "radio",
139+ "label" => "Question 2",
140+ "validate" => [
141+ "length" => [1],
142+ ],
143+ "items" => [
144+ 1 => "Yes",
145+ 0 => "No"
146+ ],
147+ "value" => 1 // Default value
148+ ],
149+ "message" => [
150+ "type" => "textarea",
151+ "label" => "Message",
152+ "validate" => [
153+ "length" => [0, 2000]
154+ ]
155+ ],
156+ "gdpr" => [
157+ "type" => "checkbox",
158+ //"label" => "GDPR",
159+ "validate" => [
160+ "length" => [1, 1],
161+ "!equal" => [1]
162+ ],
163+ "items" => [
164+ 1 => "I accept that my data will be saved according to GDPR"
165+ ]
166+ ]
167+
165168]);
166169```
167170#### 2. Set values if you want
168171If you have values from for example the database (accepts multidimensional array and object)
169172``` php
170173$fields->setValues([
171- "firstname" => "John",
172- "lastname" => "John",
173- "nested" => [
174- "item1" => 0,
175- "item2" => 1,
176- ]
174+ "firstname" => "John",
175+ "lastname" => "John",
176+ "nested" => [
177+ "item1" => 0,
178+ "item2" => 1,
179+ ]
177180]);
178181
179182```
@@ -186,7 +189,7 @@ $fields->build();
186189Now you can read the form.
187190``` php
188191echo '<form action =" index.php" method =" post" >';
189- echo $fields->getForm("userForm" );
192+ echo $fields->getForm();
190193echo "</form >";
191194```
192195#### 5. Validate form
0 commit comments