Skip to content

Commit 3785b58

Browse files
committed
add documentation
1 parent e9868ba commit 3785b58

File tree

1 file changed

+99
-49
lines changed

1 file changed

+99
-49
lines changed

src/Gustiawan/FormBuilder/Form.php

Lines changed: 99 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,56 @@
11
<?php
2-
32
namespace Gustiawan\FormBuilder;
43

4+
/**
5+
* Base Form Class
6+
*/
57
class Form
68
{
9+
10+
/**
11+
* Action for form
12+
*
13+
* @var string
14+
*/
715
public $action;
16+
17+
/**
18+
* Method For form.
19+
*
20+
* @var string
21+
*/
822
public $method;
23+
24+
/**
25+
* Form Field List
26+
*
27+
* @var array
28+
*/
929
public $fields = [];
30+
31+
/**
32+
* Form Default value
33+
*
34+
* @var array
35+
*/
1036
public $data = [];
1137

38+
/**
39+
* Button Variable
40+
*
41+
* @var array
42+
*/
1243
public $button = [
1344
"label" => "Submit",
1445
"color" => "bg-blue-400"
1546
];
1647

1748
/**
18-
* Create Form
49+
* Construct the form head with given options
1950
*
20-
* @param string $action action of form
21-
* @param string $method method of form
22-
* @return Form
51+
* @param array $options
2352
*/
24-
public function __construct($options = [])
53+
public function __construct(array $options = [])
2554
{
2655
$this->action = $options['action'];
2756
$this->method = $options['method'];
@@ -30,100 +59,98 @@ public function __construct($options = [])
3059
return $this;
3160
}
3261

62+
/**
63+
* Handle form builder
64+
*
65+
* @return void
66+
*/
3367
public function handle()
3468
{
3569
//
3670
}
3771

3872
/**
39-
* Create Input Field
73+
* Form Text input
4074
*
41-
* @param string $name name
42-
* @param any $value value
43-
* @param string $type type
44-
* @return Form
75+
* @param string $name
76+
* @param string $label
77+
* @param mixed $value
78+
* @return void
4579
*/
46-
public function text($name, $label, $value=null)
80+
public function text(string $name, string $label, mixed $value=null)
4781
{
4882
$this->fields[] = [
4983
"label" => $label,
5084
"type" => "text",
5185
"name" => $name,
5286
"value" => $value ?? (array_key_exists($name, $this->data) ? $this->data[$name] : null)
5387
];
54-
55-
return $this;
5688
}
5789

5890
/**
59-
* Create Password Field
91+
* Form Password Input
6092
*
61-
* @param string $name name
62-
* @param any $value value
63-
* @param string $type type
64-
* @return Form
93+
* @param string $name
94+
* @param string $label
95+
* @param mixed $value
96+
* @return void
6597
*/
66-
public function password($name, $label, $value=null)
98+
public function password(string $name, string $label, mixed $value=null)
6799
{
68100
$this->fields[] = [
69101
"label" => $label,
70102
"type" => "password",
71103
"name" => $name,
72104
"value" => $value ?? (array_key_exists($name, $this->data) ? $this->data[$name] : null)
73105
];
74-
75-
return $this;
76106
}
77107

78108
/**
79-
* Create Password Field
109+
* Form Date Input
80110
*
81-
* @param string $name name
82-
* @param any $value value
83-
* @param string $type type
84-
* @return Form
111+
* @param string $name
112+
* @param string $label
113+
* @param mixed $value
114+
* @return void
85115
*/
86-
public function date($name, $label, $value=null)
116+
public function date(string $name, string $label, mixed $value=null)
87117
{
88118
$this->fields[] = [
89119
"label" => $label,
90120
"type" => "date",
91121
"name" => $name,
92122
"value" => $value ?? (array_key_exists($name, $this->data) ? $this->data[$name] : null)
93123
];
94-
95-
return $this;
96124
}
97125

98126
/**
99-
* Create Password Field
127+
* Form Text Area Input
100128
*
101-
* @param string $name name
102-
* @param any $value value
103-
* @param string $type type
104-
* @return Form
129+
* @param string $name
130+
* @param string $label
131+
* @param mixed $value
132+
* @return void
105133
*/
106-
public function textArea($name, $label, $value=null)
134+
public function textArea(string $name, string $label, mixed $value=null)
107135
{
108136
$this->fields[] = [
109137
"label" => $label,
110138
"type" => "textarea",
111139
"name" => $name,
112140
"value" => $value ?? (array_key_exists($name, $this->data) ? $this->data[$name] : null)
113141
];
114-
115-
return $this;
116142
}
117143

118144
/**
119-
* Create Password Field
145+
* Form Select Box Input
120146
*
121-
* @param string $name name
122-
* @param any $value value
123-
* @param string $type type
124-
* @return Form
147+
* @param string $name
148+
* @param string $label
149+
* @param array $choices
150+
* @param mixed $value
151+
* @return void
125152
*/
126-
public function select($name, $label, $choices, $value=null)
153+
public function select(string $name, string $label, array $choices, mixed $value=null)
127154
{
128155
$this->fields[] = [
129156
"label" => $label,
@@ -132,11 +159,18 @@ public function select($name, $label, $choices, $value=null)
132159
"value" => $value ?? (array_key_exists($name, $this->data) ? $this->data[$name] : null),
133160
"choices" => $choices
134161
];
135-
136-
return $this;
137162
}
138163

139-
public function radio($name, $label, $choices, $value=null)
164+
/**
165+
* Form Radio Input
166+
*
167+
* @param string $name
168+
* @param string $label
169+
* @param array $choices
170+
* @param mixed $value
171+
* @return void
172+
*/
173+
public function radio(string $name, string $label, array $choices, mixed $value=null)
140174
{
141175
$this->fields[] = [
142176
"label" => $label,
@@ -149,7 +183,16 @@ public function radio($name, $label, $choices, $value=null)
149183
return $this;
150184
}
151185

152-
public function checkBox($name, $label, $choices, array $value=[])
186+
/**
187+
* Form Checkbox Input
188+
*
189+
* @param string $name
190+
* @param string $label
191+
* @param array $choices
192+
* @param array $value
193+
* @return void
194+
*/
195+
public function checkBox(string $name, string $label, array $choices, array $value=[])
153196
{
154197
$this->fields[] = [
155198
"label" => $label,
@@ -162,7 +205,14 @@ public function checkBox($name, $label, $choices, array $value=[])
162205
return $this;
163206
}
164207

165-
public function button($label="Submit", $color="bg-blue-500")
208+
/**
209+
* Customizing Form Button
210+
*
211+
* @param string $label
212+
* @param string $color
213+
* @return void
214+
*/
215+
public function button(string $label="Submit", string $color="bg-blue-500")
166216
{
167217
$this->button["label"] = $label;
168218
$this->button["color"] = $color;

0 commit comments

Comments
 (0)