Kotchasan Framework Documentation
Form
Form
Kotchasan\Form is for creating HTML form elements with a fluent interface.
Creation
use Kotchasan\Form;
// Create text input
$input = Form::text(['id' => 'name', 'value' => 'John']);
echo $input->render();
// Create select
$select = Form::select([
'id' => 'status',
'options' => [1 => 'Active', 0 => 'Inactive'],
'value' => 1
]);
echo $select->render();Method Reference
Input Element Methods
text(array $attributes): static
Create Input text
password(array $attributes): static
Create Input password
email(array $attributes): static
Create Input email
url(array $attributes): static
Create Input url
tel(array $attributes): static
Create Input tel (Telephone number)
number(array $attributes): static
Create Input number
integer(array $attributes): static
Create Input integer (Supports negative values)
currency(array $attributes): static
Create Input currency (Decimal numbers)
range(array $attributes): static
Create Input range
color(array $attributes): static
Create Input color
date(array $attributes): static
Create Input date
time(array $attributes): static
Create Input time
datetime(array $attributes): static
Create Input datetime
file(array $attributes): static
Create Input file
hidden(array $attributes): static
Create Input hidden
checkbox(array $attributes): static
Create Checkbox
radio(array $attributes): static
Create Radio button
select(array $attributes): static
Create Select dropdown
textarea(array $attributes): static
Create Textarea
Button Methods
button(array $attributes): static
Create generic Button
submit(array $attributes): static
Create Submit button
reset(array $attributes): static
Create Reset button
Utility Methods
render(): string
Convert Object to HTML string
get2Input(): array
Convert Query String and Parsed Body back to Hidden Inputs (For maintaining form state)
Complete Form Example
use Kotchasan\Form;
use Kotchasan\Html;
echo '<form method="post" action="save.php">';
echo Form::text([
'id' => 'name',
'label' => 'Name',
'required' => true
])->render();
echo Form::email([
'id' => 'email',
'label' => 'Email',
'required' => true
])->render();
echo Form::password([
'id' => 'password',
'label' => 'Password',
'required' => true
])->render();
echo Form::select([
'id' => 'role',
'label' => 'Role',
'options' => [
'user' => 'User',
'admin' => 'Administrator'
]
])->render();
echo Form::checkbox([
'id' => 'active',
'label' => 'Active',
'value' => 1,
'checked' => true
])->render();
echo Form::button([
'id' => 'submit',
'class' => 'button green',
'value' => 'Save'
])->render();
echo '</form>';