PHP Forms Options

Form options

method string
Form method (default: post)
method_field_name string
Name of the special method field when using methods other than GET and POST
action string
Form action (default: "")
layout string
Form layout ("plain", "table", "bootstrap" or an instance of FormLayout)
prefix mixed
Use custom prefix when generating names and ID
Other
All other options are passed directly to the form as attributes. Use it to specify attributes such as name, class, etc.

Default options

Default options for forms can be set by extending defaultOptions:

class MyForm extends Form {
	static protected function defaultOptions(){
		return [
			'layout' => 'bootstrap',
		];
	}
};
 
MyForm::create("example_default_options", function($f){
	$f->textField('name', 'My field name');
});

Field options

hint string
Description of the field. (default: none)
Other
All other attributes is passed directly to field, allowing custom attributes such as placeholder, title, etc.

Upload field

remove boolean
Adds a removal checkbox (e.g. a user avatar which is set if file is uploaded but retained if nothing is sent and removed if checkbox is checked) (default: false)
current html
HTML to preview the current uploaded data, e.g. <img src="/user/123/avatar.png"/>. (default: none)

Serialization

Most attributes is serialized using these rules:

Fork me on GitHub