Skip to content

Phalcon Forms

Updated View as Markdown

Forms\Element\AbstractElement

AbstractSource on GitHub

This is a base class for form elements

Uses Phalcon\Contracts\Forms\FormsTypes · Phalcon\Contracts\Html\HtmlTypes · Phalcon\Di\Di · Phalcon\Di\DiInterface · Phalcon\Filter\Validation\ValidatorInterface · Phalcon\Forms\Exception · Phalcon\Forms\Exceptions\FormElementNameRequired · Phalcon\Forms\Exceptions\InvalidFilterType · Phalcon\Forms\Form · Phalcon\Html\TagFactory · Phalcon\Messages\MessageInterface · Phalcon\Messages\Messages · Stringable

Method Summary

public__construct(string $name,array $attributes = [])

Constructor

publicstring__toString()

Magic method __toString renders the widget without attributes

publicElementInterfaceaddFilter(string $filter)

Adds a filter to current list of filters

publicElementInterfaceaddValidator(ValidatorInterface $validator)

Adds a validator to the element

publicElementInterfaceaddValidators(array $validators,bool $merge = true)

Adds a group of validators

publicElementInterfaceappendMessage(MessageInterface $message)

Appends a message to the internal message list

publicElementInterfaceclear()

Clears element to its default value

publicmixedgetAttribute(string $attribute,mixed $defaultValue = null)

Returns the value of an attribute if present

publicarraygetAttributes()

Returns the default attributes for the element

publicmixedgetDefault()

Returns the default value assigned to the element

publicgetFilters()

Returns the element filters

publicFormgetForm()

Returns the parent form to the element

publicstring|nullgetLabel()

Returns the element label

publicMessagesgetMessages()

Returns the messages that belongs to the element

publicstringgetName()

Returns the element name

publicTagFactory|nullgetTagFactory()

Returns the tagFactory; throws exception if not present

publicmixedgetUserOption(string $option,mixed $defaultValue = null)

Returns the value of an option if present

publicarraygetUserOptions()

Returns the options for the element

publicValidatorInterface[]getValidators()

Returns the validators registered for the element

publicmixedgetValue()

Returns the element’s value

publicboolhasMessages()

Checks whether there are messages attached to the element

publicstringlabel(array $attributes = [])

Generate the HTML to label the element

publicstringrender(array $attributes = [])

Renders the element widget returning HTML

publicElementInterfacesetAttribute(string $attribute,mixed $value)

Sets a default attribute for the element

publicElementInterfacesetAttributes(array $attributes)

Sets default attributes for the element

publicElementInterfacesetDefault(mixed $value)

Sets a default value in case the form does not use an entity

publicElementInterfacesetFilters(mixed $filters)

Sets the element filters

publicElementInterfacesetForm(Form $form)

Sets the parent form to the element

publicElementInterfacesetLabel(string $label)

Sets the element label

publicElementInterfacesetMessages(Messages $messages)

Sets the validation messages related to the element

publicElementInterfacesetName(string $name)

Sets the element name

publicstaticsetTagFactory(TagFactory $tagFactory)

Sets the TagFactory

publicElementInterfacesetUserOption(string $option,mixed $value)

Sets an option for the element

publicElementInterfacesetUserOptions(array $options)

Sets options for the element

protectedTagFactorygetLocalTagFactory()

Returns the tagFactory; throws exception if not present

Properties

protectedarray$attributes = []
protectedarray$filters = []
protectedForm|null$form = null
protectedstring|null$label = null
protectedMessages$messages
protectedstring$method = "inputText"
protectedstring$name
protectedarray$options = []
protectedTagFactory|null$tagFactory = null
protectedarray$validators = []
protectedmixed|null$value = null

Methods

Public · 34

__construct()

public function __construct(
    string $name,
    array $attributes = []
);

Constructor

__toString()

public function __toString(): string;

Magic method __toString renders the widget without attributes

addFilter()

public function addFilter( string $filter ): ElementInterface;

Adds a filter to current list of filters

addValidator()

public function addValidator( ValidatorInterface $validator ): ElementInterface;

Adds a validator to the element

addValidators()

public function addValidators(
    array $validators,
    bool $merge = true
): ElementInterface;

Adds a group of validators

appendMessage()

public function appendMessage( MessageInterface $message ): ElementInterface;

Appends a message to the internal message list

clear()

public function clear(): ElementInterface;

Clears element to its default value

getAttribute()

public function getAttribute(
    string $attribute,
    mixed $defaultValue = null
): mixed;

Returns the value of an attribute if present

getAttributes()

public function getAttributes(): array;

Returns the default attributes for the element

getDefault()

public function getDefault(): mixed;

Returns the default value assigned to the element

getFilters()

public function getFilters();

Returns the element filters

getForm()

public function getForm(): Form;

Returns the parent form to the element

getLabel()

public function getLabel(): string|null;

Returns the element label

getMessages()

public function getMessages(): Messages;

Returns the messages that belongs to the element The element needs to be attached to a form

getName()

public function getName(): string;

Returns the element name

getTagFactory()

public function getTagFactory(): TagFactory|null;

Returns the tagFactory; throws exception if not present

getUserOption()

public function getUserOption(
    string $option,
    mixed $defaultValue = null
): mixed;

Returns the value of an option if present

getUserOptions()

public function getUserOptions(): array;

Returns the options for the element

getValidators()

public function getValidators(): ValidatorInterface[];

Returns the validators registered for the element

getValue()

public function getValue(): mixed;

Returns the element’s value

hasMessages()

public function hasMessages(): bool;

Checks whether there are messages attached to the element

label()

public function label( array $attributes = [] ): string;

Generate the HTML to label the element

render()

public function render( array $attributes = [] ): string;

Renders the element widget returning HTML

setAttribute()

public function setAttribute(
    string $attribute,
    mixed $value
): ElementInterface;

Sets a default attribute for the element

setAttributes()

public function setAttributes( array $attributes ): ElementInterface;

Sets default attributes for the element

setDefault()

public function setDefault( mixed $value ): ElementInterface;

Sets a default value in case the form does not use an entity or there is no value available for the element in _POST

setFilters()

public function setFilters( mixed $filters ): ElementInterface;

Sets the element filters

setForm()

public function setForm( Form $form ): ElementInterface;

Sets the parent form to the element

setLabel()

public function setLabel( string $label ): ElementInterface;

Sets the element label

setMessages()

public function setMessages( Messages $messages ): ElementInterface;

Sets the validation messages related to the element

setName()

public function setName( string $name ): ElementInterface;

Sets the element name

setTagFactory()

public function setTagFactory( TagFactory $tagFactory ): static;

Sets the TagFactory

setUserOption()

public function setUserOption(
    string $option,
    mixed $value
): ElementInterface;

Sets an option for the element

setUserOptions()

public function setUserOptions( array $options ): ElementInterface;

Sets options for the element

Protected · 1

getLocalTagFactory()

protected function getLocalTagFactory(): TagFactory;

Returns the tagFactory; throws exception if not present

Forms\Element\Check

ClassSource on GitHub

Component INPUT[type=check] for forms

Method Summary

Properties

protectedstring$method = "inputCheckbox"
protectedmixed$uncheckedValue = null
protectedbool$uncheckedValueSet = false

Methods

Public · 3

getUncheckedValue()

public function getUncheckedValue(): mixed;

Returns the value to bind when the checkbox is absent from submitted data. Only meaningful when hasUncheckedValue() is true.

hasUncheckedValue()

public function hasUncheckedValue(): bool;

Whether an “unchecked value” has been explicitly registered.

setUncheckedValue()

public function setUncheckedValue( mixed $value ): static;

Registers a value to bind when the checkbox is absent from submitted data (the typical browser behavior for an unchecked input). Without this opt-in, an unchecked checkbox leaves the entity property untouched. See cphalcon issue #16982.

Forms\Element\CheckGroup

ClassSource on GitHub

Component for a group of INPUT[type=checkbox] elements.

The name is automatically suffixed with [] when not already present so that PHP collects all checked values into an array on form submission.

Options are passed as an associative array: [‘value’ => ‘Label’] or with per-item attributes: [‘value’ => [‘label’ => ‘Label’, ‘disabled’ => true]]

Uses Phalcon\Contracts\Forms\FormsTypes · Phalcon\Contracts\Html\HtmlTypes · Phalcon\Html\TagFactory

Method Summary

Properties

protectedarray$optionsValues = []

Methods

Public · 4

__construct()

public function __construct(
    string $name,
    array $options = [],
    array $attributes = []
);

Constructor

getOptions()

public function getOptions(): array;

Returns the group options

render()

public function render( array $attributes = [] ): string;

Renders the checkbox group returning HTML

setOptions()

public function setOptions( array $options ): ElementInterface;

Sets the group options

Forms\Element\Date

ClassSource on GitHub

Component INPUT[type=date] for forms

Properties

protectedstring$method = "inputDate"

Forms\Element\ElementInterface

InterfaceSource on GitHub

Interface for Phalcon\Forms\Element classes

  • Phalcon\Forms\Element\ElementInterface

Uses Phalcon\Contracts\Forms\FormsTypes · Phalcon\Contracts\Html\HtmlTypes · Phalcon\Filter\Validation\ValidatorInterface · Phalcon\Forms\Form · Phalcon\Messages\MessageInterface · Phalcon\Messages\Messages

Method Summary

publicElementInterfaceaddFilter(string $filter)

Adds a filter to current list of filters

publicElementInterfaceaddValidator(ValidatorInterface $validator)

Adds a validator to the element

publicElementInterfaceaddValidators(array $validators,bool $merge = true)

Adds a group of validators

publicElementInterfaceappendMessage(MessageInterface $message)

Appends a message to the internal message list

publicElementInterfaceclear()

Clears every element in the form to its default value

publicmixedgetAttribute(string $attribute,mixed $defaultValue = null)

Returns the value of an attribute if present

publicarraygetAttributes()

Returns the default attributes for the element

publicmixedgetDefault()

Returns the default value assigned to the element

publicgetFilters()

Returns the element’s filters

publicFormgetForm()

Returns the parent form to the element

publicstring|nullgetLabel()

Returns the element’s label

publicMessagesgetMessages()

Returns the messages that belongs to the element

publicstringgetName()

Returns the element’s name

publicmixedgetUserOption(string $option,mixed $defaultValue = null)

Returns the value of an option if present

publicarraygetUserOptions()

Returns the options for the element

publicValidatorInterface[]getValidators()

Returns the validators registered for the element

publicmixedgetValue()

Returns the element’s value

publicboolhasMessages()

Checks whether there are messages attached to the element

publicstringlabel()

Generate the HTML to label the element

publicstringrender(array $attributes = [])

Renders the element widget

publicElementInterfacesetAttribute(string $attribute,mixed $value)

Sets a default attribute for the element

publicElementInterfacesetAttributes(array $attributes)

Sets default attributes for the element

publicElementInterfacesetDefault(mixed $value)

Sets a default value in case the form does not use an entity

publicElementInterfacesetFilters(mixed $filters)

Sets the element’s filters

publicElementInterfacesetForm(Form $form)

Sets the parent form to the element

publicElementInterfacesetLabel(string $label)

Sets the element label

publicElementInterfacesetMessages(Messages $messages)

Sets the validation messages related to the element

publicElementInterfacesetName(string $name)

Sets the element’s name

publicElementInterfacesetUserOption(string $option,mixed $value)

Sets an option for the element

publicElementInterfacesetUserOptions(array $options)

Sets options for the element

Methods

Public · 30

addFilter()

public function addFilter( string $filter ): ElementInterface;

Adds a filter to current list of filters

addValidator()

public function addValidator( ValidatorInterface $validator ): ElementInterface;

Adds a validator to the element

addValidators()

public function addValidators(
    array $validators,
    bool $merge = true
): ElementInterface;

Adds a group of validators

appendMessage()

public function appendMessage( MessageInterface $message ): ElementInterface;

Appends a message to the internal message list

clear()

public function clear(): ElementInterface;

Clears every element in the form to its default value

getAttribute()

public function getAttribute(
    string $attribute,
    mixed $defaultValue = null
): mixed;

Returns the value of an attribute if present

getAttributes()

public function getAttributes(): array;

Returns the default attributes for the element

getDefault()

public function getDefault(): mixed;

Returns the default value assigned to the element

getFilters()

public function getFilters();

Returns the element’s filters

getForm()

public function getForm(): Form;

Returns the parent form to the element

getLabel()

public function getLabel(): string|null;

Returns the element’s label

getMessages()

public function getMessages(): Messages;

Returns the messages that belongs to the element The element needs to be attached to a form

getName()

public function getName(): string;

Returns the element’s name

getUserOption()

public function getUserOption(
    string $option,
    mixed $defaultValue = null
): mixed;

Returns the value of an option if present

getUserOptions()

public function getUserOptions(): array;

Returns the options for the element

getValidators()

public function getValidators(): ValidatorInterface[];

Returns the validators registered for the element

getValue()

public function getValue(): mixed;

Returns the element’s value

hasMessages()

public function hasMessages(): bool;

Checks whether there are messages attached to the element

label()

public function label(): string;

Generate the HTML to label the element

render()

public function render( array $attributes = [] ): string;

Renders the element widget

setAttribute()

public function setAttribute(
    string $attribute,
    mixed $value
): ElementInterface;

Sets a default attribute for the element

setAttributes()

public function setAttributes( array $attributes ): ElementInterface;

Sets default attributes for the element

setDefault()

public function setDefault( mixed $value ): ElementInterface;

Sets a default value in case the form does not use an entity or there is no value available for the element in _POST

setFilters()

public function setFilters( mixed $filters ): ElementInterface;

Sets the element’s filters

setForm()

public function setForm( Form $form ): ElementInterface;

Sets the parent form to the element

setLabel()

public function setLabel( string $label ): ElementInterface;

Sets the element label

setMessages()

public function setMessages( Messages $messages ): ElementInterface;

Sets the validation messages related to the element

setName()

public function setName( string $name ): ElementInterface;

Sets the element’s name

setUserOption()

public function setUserOption(
    string $option,
    mixed $value
): ElementInterface;

Sets an option for the element

setUserOptions()

public function setUserOptions( array $options ): ElementInterface;

Sets options for the element

Forms\Element\Email

ClassSource on GitHub

Component INPUT[type=email] for forms

Properties

protectedstring$method = "inputEmail"

Forms\Element\File

ClassSource on GitHub

Component INPUT[type=file] for forms

Properties

protectedstring$method = "inputFile"

Forms\Element\Hidden

ClassSource on GitHub

Component INPUT[type=hidden] for forms

Properties

protectedstring$method = "inputHidden"

Forms\Element\Numeric

ClassSource on GitHub

Component INPUT[type=number] for forms

Properties

protectedstring$method = "inputNumeric"

Forms\Element\Password

ClassSource on GitHub

Component INPUT[type=password] for forms

Properties

protectedstring$method = "inputPassword"

Forms\Element\Radio

ClassSource on GitHub

Component INPUT[type=radio] for forms

Properties

protectedstring$method = "inputRadio"

Forms\Element\RadioGroup

ClassSource on GitHub

Component for a group of INPUT[type=radio] elements.

Options are passed as an associative array: [‘value’ => ‘Label’] or with per-item attributes: [‘value’ => [‘label’ => ‘Label’, ‘disabled’ => true]]

Uses Phalcon\Contracts\Forms\FormsTypes · Phalcon\Contracts\Html\HtmlTypes · Phalcon\Html\Helper\Input\RadioGroup · Phalcon\Html\TagFactory

Method Summary

Properties

protectedarray$optionsValues = []

Methods

Public · 4

__construct()

public function __construct(
    string $name,
    array $options = [],
    array $attributes = []
);

Constructor

getOptions()

public function getOptions(): array;

Returns the group options

render()

public function render( array $attributes = [] ): string;

Renders the radio group returning HTML

setOptions()

public function setOptions( array $options ): ElementInterface;

Sets the group options

Forms\Element\Select

ClassSource on GitHub

Component SELECT (choice) for forms

Uses Phalcon\Contracts\Forms\FormsTypes · Phalcon\Contracts\Html\HtmlTypes · Phalcon\Tag\Select

Method Summary

Properties

protectedarray|object|null$optionsValues = null

Methods

Public · 5

__construct()

public function __construct(
    string $name,
    mixed $options = null,
    array $attributes = []
);

Constructor

addOption()

public function addOption( mixed $option ): ElementInterface;

Adds an option to the current options

getOptions()

public function getOptions();

Returns the choices’ options

render()

public function render( array $attributes = [] ): string;

Renders the element widget returning HTML

setOptions()

public function setOptions( mixed $options ): ElementInterface;

Set the choice’s options

Protected · 1

prepareAttributes()

protected function prepareAttributes( array $attributes = [] ): array;

Returns an array of prepared attributes for Phalcon\Html\TagFactory helpers according to the element parameters

Forms\Element\Submit

ClassSource on GitHub

Component INPUT[type=submit] for forms

Properties

protectedstring$method = "inputSubmit"

Forms\Element\Text

ClassSource on GitHub

Component INPUT[type=text] for forms

Forms\Element\TextArea

ClassSource on GitHub

Component TEXTAREA for forms

Properties

protectedstring$method = "inputTextarea"

Forms\Exception

ClassSource on GitHub

Exceptions thrown in Phalcon\Forms will use this class

Method Summary

Methods

Public · 2

tagFactoryNotFound()

public static function tagFactoryNotFound(): self;

usingParameterRequired()

public static function usingParameterRequired(): self;

Forms\Exceptions\ElementNotInForm

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Forms\Exceptions\FormElementNameRequired

ClassSource on GitHub
  • \InvalidArgumentException
    • Phalcon\Forms\Exceptions\FormElementNameRequired

Uses InvalidArgumentException

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Forms\Exceptions\FormNotInLocator

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Forms\Exceptions\FormNotRegistered

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Forms\Exceptions\InvalidEntity

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Forms\Exceptions\InvalidFilterType

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Forms\Exceptions\InvalidJsonSchema

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $detail );

Forms\Exceptions\JsonSchemaNotArray

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Forms\Exceptions\NoFormElements

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Forms\Exceptions\SchemaEntryMissingKey

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    int $index,
    string $key
);

Forms\Exceptions\SchemaEntryNotArray

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( int $index );

Forms\Exceptions\UnknownFormElementType

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $type );

Forms\Exceptions\YamlExtensionRequired

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Forms\Exceptions\YamlSchemaNotArray

ClassSource on GitHub

Uses Phalcon\Forms\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Forms\Form

ClassSource on GitHub

This component allows to build forms using an object-oriented interface

@implements Iterator<int, ElementInterface>

Uses Countable · Iterator · Phalcon\Contracts\Forms\FormsTypes · Phalcon\Contracts\Forms\Schema · Phalcon\Contracts\Html\HtmlTypes · Phalcon\Di\DiInterface · Phalcon\Di\Injectable · Phalcon\Filter\FilterInterface · Phalcon\Filter\Validation · Phalcon\Filter\Validation\ValidationInterface · Phalcon\Forms\Element\Check · Phalcon\Forms\Element\ElementInterface · Phalcon\Forms\Exceptions\ElementNotInForm · Phalcon\Forms\Exceptions\InvalidEntity · Phalcon\Forms\Exceptions\NoFormElements · Phalcon\Html\Attributes · Phalcon\Html\Attributes\AttributesInterface · Phalcon\Html\TagFactory · Phalcon\Messages\Messages · Phalcon\Support\Settings · Phalcon\Tag

Method Summary

public__construct(mixed $entity = null,array $userOptions = [])

Phalcon\Forms\Form constructor

publicstaticadd(ElementInterface $element,string|null $position = null,bool|null $type = null)

Adds an element to the form

publicstaticbind(array $data,mixed $entity = null,array $whitelist = [])

Binds data to the entity

publicstaticclear(mixed $fields = null)

Clears every element in the form to its default value

publicintcount()

Returns the number of elements in the form

publicmixedcurrent()

Returns the current element in the iterator

publicElementInterfaceget(string $name)

Returns an element added to the form by its name

publicstringgetAction()

Returns the form’s action

publicAttributesgetAttributes()

Get Form attributes collection

publicElementInterface[]getElements()

Returns the form elements added to the form

publicgetEntity()

Returns the entity related to the model

publicmixed|nullgetFilteredValue(string $name)

Gets a value from the internal filtered data or calls getValue(name)

publicstringgetLabel(string $name)

Returns a label for an element

publicMessagesgetMessages()

Returns the messages generated in the validation.

publicMessagesgetMessagesFor(string $name)

Returns the messages generated for a specific element

publicTagFactory|nullgetTagFactory()

Returns the tagFactory object

publicmixedgetUserOption(string $option,mixed $defaultValue = null)

Returns the value of an option if present

publicarraygetUserOptions()

Returns the options for the element

publicValidationInterface|nullgetValidation()

return ValidationInterface|null

publicmixed|nullgetValue(string $name)

Gets a value from the internal related entity or from the default value

publicarraygetWhitelist()publicboolhas(string $name)

Check if the form contains an element

publicboolhasMessagesFor(string $name)

Check if messages were generated for a specific element

publicboolisValid(mixed $data = null,mixed $entity = null,array $whitelist = [])

Validates the form

publicintkey()

Returns the current position/key in the iterator

publicstringlabel(string $name,array $attributes = [])

Generate the label of an element added to the form including HTML

publicstaticload(Schema $schema,FormsLocator $locator)

Loads elements into the form from a Schema source.

publicvoidnext()

Moves the internal iteration pointer to the next position

publicboolremove(string $name)

Removes an element from the form

publicstringrender(string $name,array $attributes = [])

Renders a specific item in the form

publicvoidrewind()

Rewinds the internal iterator

publicstaticsetAction(string $action)

Sets the form’s action

publicstaticsetAttributes(Attributes $attributes)

Set form attributes collection

publicstaticsetEntity(mixed $entity)

Sets the entity related to the model

publicstaticsetTagFactory(TagFactory $tagFactory)

Sets the tagFactory for the form

publicstaticsetUserOption(string $option,mixed $value)

Sets an option for the form

publicstaticsetUserOptions(array $options)

Sets options for the element

publicstaticsetValidation(ValidationInterface $validation)

Sets the default validation

publicstaticsetWhitelist(array $whitelist)

Sets the default whitelist

publicboolvalid()

Check if the current element in the iterator is valid

Properties

protectedAttributesInterface|null$attributes = null
protectedarray$data = []
protectedarray$elements = []
protectedarray$elementsIndexed = []
protectedobject|null$entity = null
protectedarray$filteredData = []
protectedMessages$messages
protectedarray$options = []
protectedint$position = 0
protectedTagFactory|null$tagFactory = null
protectedValidationInterface|null$validation = null
protectedarray$whitelist = []

Methods

Public · 40

__construct()

public function __construct(
    mixed $entity = null,
    array $userOptions = []
);

Phalcon\Forms\Form constructor

add()

public function add(
    ElementInterface $element,
    string|null $position = null,
    bool|null $type = null
): static;

Adds an element to the form

bind()

public function bind(
    array $data,
    mixed $entity = null,
    array $whitelist = []
): static;

Binds data to the entity

clear()

public function clear( mixed $fields = null ): static;

Clears every element in the form to its default value

count()

public function count(): int;

Returns the number of elements in the form

current()

public function current(): mixed;

Returns the current element in the iterator

get()

public function get( string $name ): ElementInterface;

Returns an element added to the form by its name

getAction()

public function getAction(): string;

Returns the form’s action

getAttributes()

public function getAttributes(): Attributes;

Get Form attributes collection

getElements()

public function getElements(): ElementInterface[];

Returns the form elements added to the form

getEntity()

public function getEntity();

Returns the entity related to the model

getFilteredValue()

public function getFilteredValue( string $name ): mixed|null;

Gets a value from the internal filtered data or calls getValue(name)

getLabel()

public function getLabel( string $name ): string;

Returns a label for an element

getMessages()

public function getMessages(): Messages;

Returns the messages generated in the validation.

if ($form->isValid($_POST) == false) {
    $messages = $form->getMessages();

    foreach ($messages as $message) {
        echo $message, "<br>";
    }
}

getMessagesFor()

public function getMessagesFor( string $name ): Messages;

Returns the messages generated for a specific element

getTagFactory()

public function getTagFactory(): TagFactory|null;

Returns the tagFactory object

getUserOption()

public function getUserOption(
    string $option,
    mixed $defaultValue = null
): mixed;

Returns the value of an option if present

getUserOptions()

public function getUserOptions(): array;

Returns the options for the element

getValidation()

public function getValidation(): ValidationInterface|null;

return ValidationInterface|null

getValue()

public function getValue( string $name ): mixed|null;

Gets a value from the internal related entity or from the default value

getWhitelist()

public function getWhitelist(): array;

has()

public function has( string $name ): bool;

Check if the form contains an element

hasMessagesFor()

public function hasMessagesFor( string $name ): bool;

Check if messages were generated for a specific element

isValid()

public function isValid(
    mixed $data = null,
    mixed $entity = null,
    array $whitelist = []
): bool;

Validates the form

key()

public function key(): int;

Returns the current position/key in the iterator

label()

public function label(
    string $name,
    array $attributes = []
): string;

Generate the label of an element added to the form including HTML

load()

public function load(
    Schema $schema,
    FormsLocator $locator
): static;

Loads elements into the form from a Schema source.

Each definition in the schema must have at least ‘type’ and ‘name’. The locator resolves the type string to an element factory; custom types can be registered on the locator with setElement().

next()

public function next(): void;

Moves the internal iteration pointer to the next position

remove()

public function remove( string $name ): bool;

Removes an element from the form

render()

public function render(
    string $name,
    array $attributes = []
): string;

Renders a specific item in the form

rewind()

public function rewind(): void;

Rewinds the internal iterator

setAction()

public function setAction( string $action ): static;

Sets the form’s action

setAttributes()

public function setAttributes( Attributes $attributes ): static;

Set form attributes collection

setEntity()

public function setEntity( mixed $entity ): static;

Sets the entity related to the model

setTagFactory()

public function setTagFactory( TagFactory $tagFactory ): static;

Sets the tagFactory for the form

setUserOption()

public function setUserOption(
    string $option,
    mixed $value
): static;

Sets an option for the form

setUserOptions()

public function setUserOptions( array $options ): static;

Sets options for the element

setValidation()

public function setValidation( ValidationInterface $validation ): static;

Sets the default validation

setWhitelist()

public function setWhitelist( array $whitelist ): static;

Sets the default whitelist

valid()

public function valid(): bool;

Check if the current element in the iterator is valid

Forms\FormsLocator

ClassSource on GitHub

A closure-based registry for named forms and element type factories.

Form registry (get/has/set): Each entry is a callable fn(?object $entity): Form. Without an entity the resolved form is cached; with an entity a fresh form is always produced.

Element registry (getElement/hasElement/setElement): Maps type strings (e.g. ‘text’, ‘email’) to factories used by Form::load(). Each callable has the signature fn(string $name, array $options, array $attributes): ElementInterface. Default types are seeded by getDefaultServices(). Users may add or override types with setElement().

  • Phalcon\Forms\FormsLocator

Uses Phalcon\Contracts\Forms\FormsTypes · Phalcon\Forms\Element\Check · Phalcon\Forms\Element\CheckGroup · Phalcon\Forms\Element\Date · Phalcon\Forms\Element\ElementInterface · Phalcon\Forms\Element\Email · Phalcon\Forms\Element\File · Phalcon\Forms\Element\Hidden · Phalcon\Forms\Element\Numeric · Phalcon\Forms\Element\Password · Phalcon\Forms\Element\Radio · Phalcon\Forms\Element\RadioGroup · Phalcon\Forms\Element\Select · Phalcon\Forms\Element\Submit · Phalcon\Forms\Element\Text · Phalcon\Forms\Element\TextArea · Phalcon\Forms\Exceptions\FormNotInLocator · Phalcon\Forms\Exceptions\UnknownFormElementType

Method Summary

Methods

Public · 7

__construct()

public function __construct( array $definitions = [] );

get()

public function get(
    string $name,
    mixed $entity = null
): Form;

Returns the named form.

Without an entity the result is lazily created and cached. With an entity a fresh form is always produced.

getElement()

public function getElement( string $type );

Returns the factory callable for the given element type.

has()

public function has( string $name ): bool;

Checks whether a named form factory is registered.

hasElement()

public function hasElement( string $type ): bool;

Checks whether an element type is registered.

set()

public function set(
    string $name,
    mixed $factory
): void;

Registers or replaces a named form factory.

The callable must accept one argument (?object $entity) and return a Form instance. Replacing a registration clears any cached instance so the next get() call rebuilds from the new factory.

setElement()

public function setElement(
    string $type,
    mixed $factory
): void;

Registers or replaces an element type factory.

The callable must accept (string $name, array $options, array $attributes) and return an ElementInterface instance.

Protected · 1

getDefaultServices()

protected function getDefaultServices(): array;

Returns the built-in element type factories.

Each value is a callable: fn(string $name, array $options, array $attributes): ElementInterface

Forms\Loader\ArrayLoader

ClassSource on GitHub

Supplies form element definitions from a PHP array.

Uses Phalcon\Contracts\Forms\Schema · Phalcon\Forms\Exception · Phalcon\Forms\Exceptions\SchemaEntryMissingKey · Phalcon\Forms\Exceptions\SchemaEntryNotArray

Method Summary

Properties

protectedarray$definitions

Methods

Public · 2

__construct()

public function __construct( array $definitions );

load()

public function load(): array;
Protected · 1

validateDefinition()

protected function validateDefinition(
    mixed $definition,
    int $index
): void;

Forms\Loader\JsonLoader

ClassSource on GitHub

Supplies form element definitions from a JSON string or file.

When $source looks like an existing, readable file path it is read from disk first; otherwise the value is treated as a raw JSON string.

Uses InvalidArgumentException · Phalcon\Contracts\Forms\Schema · Phalcon\Forms\Exception · Phalcon\Forms\Exceptions\InvalidJsonSchema · Phalcon\Forms\Exceptions\JsonSchemaNotArray · Phalcon\Support\Helper\Json\Decode · Phalcon\Traits\Php\FileTrait

Method Summary

Properties

protectedstring$source

Methods

Public · 2

__construct()

public function __construct( string $source );

load()

public function load(): array;

Forms\Loader\YamlLoader

ClassSource on GitHub

Supplies form element definitions from a YAML string or file.

Requires the PHP yaml extension (pecl/yaml).

When $source is an existing, readable file path the file is parsed directly; otherwise the value is treated as a raw YAML string.

Uses Phalcon\Contracts\Forms\Schema · Phalcon\Forms\Exception · Phalcon\Forms\Exceptions\YamlExtensionRequired · Phalcon\Forms\Exceptions\YamlSchemaNotArray · Phalcon\Traits\Php\InfoTrait

Method Summary

Properties

protectedstring$source

Methods

Public · 2

__construct()

public function __construct( string $source );

load()

public function load(): array;

Forms\Manager

ClassSource on GitHub

Forms Manager

  • Phalcon\Forms\Manager

Uses Phalcon\Contracts\Forms\Schema · Phalcon\Forms\Exceptions\FormNotRegistered · Phalcon\Forms\Form

Method Summary

Properties

protectedarray$forms = []
protectedFormsLocator$locator

Methods

Public · 7

__construct()

public function __construct( FormsLocator|null $locator = null );

Manager constructor.

create()

public function create(
    string $name,
    mixed $entity = null
): Form;

Creates a form registering it in the forms manager

get()

public function get( string $name ): Form;

Returns a form by its name

getLocator()

public function getLocator(): FormsLocator;

Returns the FormsLocator instance.

has()

public function has( string $name ): bool;

Checks if a form is registered in the forms manager

loadForm()

public function loadForm(
    string $name,
    Schema $schema,
    mixed $entity = null
): Form;

Creates a form from a Schema source, registers it in the manager, and registers a factory in the locator for entity-aware retrieval.

set()

public function set(
    string $name,
    Form $form
): static;

Registers a form in the Forms Manager

Navigation

Type to search…

↑↓ navigate↵ selectEsc close