Class Form (namespace Nette\Forms)


Creates, validates and renders HTML forms.

Direct Known Sub-classes:

AppForm
Constructor Summary
public
__construct ([$name = NULL], [$parent = NULL])
Form constructor.
Method Summary
void
addError (string $message)
Adds error message to the list.
FormGroup
addGroup ([string $label = NULL], [bool $setAsCurrent = TRUE])
Adds fieldset group to the form.
void
addProtection ([string $message = NULL], [int $timeout = NULL])
Cross-Site Request Forgery (CSRF) form protection.
void
addTracker (string $name)
Adds distinguishing mark.
protected static array
arrayAppend (array $arr1, array $arr2)
Recursively appends elements of remaining keys from the second array to the first.
protected void
This method will be called when the component (or component's parent) becomes attached to a monitored object. Do not call this method yourself.
void
mixed
Returns form's action.
Html
Returns form's HTML element template.
string
Returns the encoding.
array
Returns validation errors.
FormGroup
getGroup (string $name)
Returns the specified group.
array
Returns all defined groups.
protected IHttpRequest
string
Returns form's method.
IFormRenderer|NULL
Returns form renderer.
protected Session
ITranslator|NULL
Returns translate adapter.
array
Returns the values submitted by the form.
bool
bool
Was form populated by setDefaults() or processHttpRequest() yet?
ISubmitterControl|FALSE
Tells if the form was submitted.
bool
isValid ()
Is form valid?
protected void
loadHttpData ($data)
Fill-in the form with HTTP data. Doesn't check if form was submitted.
void
processHttpRequest ([IHttpRequest $httpRequest = NULL])
Detects form submission and loads HTTP values.
void
render ()
Renders form.
void
setAction (mixed $url)
Sets form's action.
void
setDefaults (array $values, [bool $erase = FALSE])
Fill-in with default values.
void
setEncoding (string $value)
Set the encoding for the values.
void
setMethod (string $method)
Sets form's method.
void
setRenderer (IFormRenderer $renderer)
Sets form renderer.
void
Sets the submittor control.
void
setTranslator ([$translator = NULL])
Sets translate adapter.
protected void
submit ()
Fires submit/click events.
void
Performs the server side validation.
string
Renders form to string.
Methods Inherited From FormContainer
FormContainer::addButton(), FormContainer::addCheckbox(), FormContainer::addComponent(), FormContainer::addContainer(), FormContainer::addFile(), FormContainer::addHidden(), FormContainer::addImage(), FormContainer::addMultiSelect(), FormContainer::addPassword(), FormContainer::addRadioList(), FormContainer::addRepeater(), FormContainer::addSelect(), FormContainer::addSubmit(), FormContainer::addText(), FormContainer::addTextArea(), FormContainer::getControls(), FormContainer::offsetExists(), FormContainer::offsetGet(), FormContainer::offsetSet(), FormContainer::offsetUnset(), FormContainer::setCurrentGroup()
Methods Inherited From ComponentContainer
ComponentContainer::addComponent(), ComponentContainer::createComponent(), ComponentContainer::getComponent(), ComponentContainer::getComponents(), ComponentContainer::isCloning(), ComponentContainer::removeComponent(), ComponentContainer::validateChildComponent(), ComponentContainer::__clone()
Methods Inherited From Component
Component::__construct(), Component::attached(), Component::detached(), Component::getName(), Component::getParent(), Component::getService(), Component::getServiceLocator(), Component::lookup(), Component::lookupPath(), Component::monitor(), Component::setParent(), Component::setServiceLocator(), Component::validateParent(), Component::__clone(), Component::__wakeup()
Methods Inherited From Object
Object::extensionMethod(), Object::getClass(), Object::getReflection(), Object::__call(), Object::__callStatic(), Object::__get(), Object::__isset(), Object::__set(), Object::__unset()
Constant Summary
string EMAIL ':email'

line 58

operation name
string EQUAL ':equal'

line 46

operation name
string FILLED ':filled'

line 48

operation name
string FLOAT ':float'

line 63

operation name
string INTEGER ':integer'

line 61

operation name
string IS_IN ':equal'

line 47

operation name
string LENGTH ':length'

line 57

operation name
string MAX_FILE_SIZE ':fileSize'

line 67

operation name
string MAX_LENGTH ':maxLength'

line 56

operation name
string MIME_TYPE ':mimeType'

line 68

operation name
string MIN_LENGTH ':minLength'

line 55

operation name
string NUMERIC ':integer'

line 62

operation name
string PROTECTOR_ID '_token_'

line 78

protection token ID
string RANGE ':range'

line 64

operation name
string REGEXP ':regexp'

line 60

operation name
string SCRIPT 'Nette\Forms\InstantClientScript::javascript'

line 71

operation name
string SUBMITTED ':submitted'

line 52

operation name
string TRACKER_ID '_form_'

line 75

tracker ID
string URL ':url'

line 59

operation name
string VALID ':valid'

line 49

operation name
Variable Summary
protected bool $isPost TRUE

line 87

array $onInvalidSubmit

line 84

of event handlers; Occurs when the form is submitted and not validated; function(Form $sender)
array $onSubmit

line 81

of event handlers; Occurs when the form is submitted and successfully validated; function(Form $sender)
protected mixed $submittedBy

line 90


Constructor Details

line 121

__construct

public __construct ([$name = NULL], [$parent = NULL])

Form constructor.

Input
$name
$parent
Method Details

line 615

addError

public void addError (string $message)

Adds error message to the list.

Input
string $message error message
Output
void  

line 233

addGroup

public FormGroup addGroup ([string $label = NULL], [bool $setAsCurrent = TRUE])

Adds fieldset group to the form.

Input
string $label label
bool $setAsCurrent set this group as current
Output
FormGroup  

line 211

addProtection

public void addProtection ([string $message = NULL], [int $timeout = NULL])

Cross-Site Request Forgery (CSRF) form protection.

Input
string $message
int $timeout
Output
void  

line 198

addTracker

public void addTracker (string $name)

Adds distinguishing mark.

Input
string $name
Output
void  

line 557

arrayAppend

protected static array arrayAppend (array $arr1, array $arr2)

Recursively appends elements of remaining keys from the second array to the first.

Input
array $arr1
array $arr2
Output
array  

line 138

attached

protected void attached (IComponent $obj)

This method will be called when the component (or component's parent) becomes attached to a monitored object. Do not call this method yourself.

Overridden in child classes as:

Input
IComponent $obj
Output
void  

line 649

cleanErrors

public void cleanErrors ()

Output
void  

line 163

getAction

public mixed getAction ()

Returns form's action.

Output
mixed URI

line 665

getElementPrototype

public Html getElementPrototype ()

Returns form's HTML element template.

Output
Html  

line 294

getEncoding

public string getEncoding ()

Returns the encoding.

Output
string  

line 629

getErrors

public array getErrors ()

Returns validation errors.

Output
array  

line 268

getGroup

public FormGroup getGroup (string $name)

Returns the specified group.

Input
string $name name
Output
FormGroup  

line 256

getGroups

public array getGroups ()

Returns all defined groups.

Output
array of FormGroup

line 749

getHttpRequest

protected IHttpRequest getHttpRequest ()

Output
IHttpRequest  

line 186

getMethod

public string getMethod ()

Returns form's method.

Output
string get | post

line 688

getRenderer

public IFormRenderer|NULL getRenderer ()

Returns form renderer.

Output
IFormRenderer|NULL  

line 759

getSession

protected Session getSession ()

Output
Session  

line 321

getTranslator

public ITranslator|NULL getTranslator ()

Returns translate adapter.

Output
ITranslator|NULL  

line 522

getValues

public array getValues ()

Returns the values submitted by the form.

Output
array  

line 639

hasErrors

public bool hasErrors ()

Output
bool  

line 511

isPopulated

public bool isPopulated ()

Was form populated by setDefaults() or processHttpRequest() yet?

Output
bool  

line 336

isSubmitted

public ISubmitterControl|FALSE isSubmitted ()

Tells if the form was submitted.

Output
ISubmitterControl|FALSE submittor control

line 578

isValid

public bool isValid ()

Is form valid?

Output
bool  

line 478

loadHttpData

protected void loadHttpData ($data)

Fill-in the form with HTTP data. Doesn't check if form was submitted.

Input
$data user data
Output
void  

line 364

processHttpRequest

public void processHttpRequest ([IHttpRequest $httpRequest = NULL])

Detects form submission and loads HTTP values.

Overridden in child classes as:

Input
IHttpRequest $httpRequest optional request object
Output
void  

line 702

render

public void render ()

Renders form.

Output
void  

line 152

setAction

public void setAction (mixed $url)

Sets form's action.

Input
mixed $url URI
Output
void  

line 435

setDefaults

public void setDefaults (array $values, [bool $erase = FALSE])

Fill-in with default values.

Input
array $values values used to fill the form
bool $erase erase other controls
Output
void  

line 280

setEncoding

public void setEncoding (string $value)

Set the encoding for the values.

Input
string $value
Output
void  

line 175

setMethod

public void setMethod (string $method)

Sets form's method.

Input
string $method get | post
Output
void  

line 677

setRenderer

public void setRenderer (IFormRenderer $renderer)

Sets form renderer.

Input
IFormRenderer $renderer
Output
void  

line 352

setSubmittedBy

public void setSubmittedBy ([ISubmitterControl $by = NULL])

Sets the submittor control.

Input
ISubmitterControl $by
Output
void  

line 310

setTranslator

public void setTranslator ([$translator = NULL])

Sets translate adapter.

Input
$translator
Output
void  

line 401

submit

protected void submit ()

Fires submit/click events.

Output
void  

line 592

validate

public void validate ()

Performs the server side validation.

Output
void  

line 721

__toString

public string __toString ()

Renders form to string.

Output
string