FileAccess Orion

FormHelper extends Helper
in package

FormHelper provides helpers to help display forms.

Tags
author

Fabien Potencier fabien@symfony.com

author

Bernhard Schussek bschussek@gmail.com

deprecated

since version 4.3, to be removed in 5.0; use Twig instead.

Table of Contents

$renderer  : mixed
__construct()  : mixed
block()  : string
Renders a block of the template.
csrfToken()  : string
Returns a CSRF token.
end()  : string
Renders the form end tag.
errors()  : string
Renders the errors of the given view.
form()  : string
Renders the HTML for a form.
getName()  : mixed
{@inheritdoc}
help()  : string
Renders the help of the given view.
humanize()  : mixed
label()  : string
Renders the label of the given view.
rest()  : string
Renders views which have not already been rendered.
row()  : string
Renders the entire form field "row".
setTheme()  : mixed
Sets a theme for a given view.
start()  : string
Renders the form start tag.
widget()  : string
Renders the HTML for a given view.

Properties

Methods

__construct()

public __construct(FormRendererInterface $renderer) : mixed
Parameters
$renderer : FormRendererInterface
Return values
mixed

block()

Renders a block of the template.

public block(FormView $view, string $blockName[, array<string|int, mixed> $variables = [] ]) : string
Parameters
$view : FormView
$blockName : string

The name of the block to render

$variables : array<string|int, mixed> = []

The variable to pass to the template

Return values
string

The HTML markup

csrfToken()

Returns a CSRF token.

public csrfToken(string $tokenId) : string

Use this helper for CSRF protection without the overhead of creating a form.

echo $view['form']->csrfToken('rm_user_'.$user->getId());

Check the token in your action using the same CSRF token id.

// $csrfProvider being an instance of Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface
if (!$csrfProvider->isCsrfTokenValid('rm_user_'.$user->getId(), $token)) {
    throw new \RuntimeException('CSRF attack detected.');
}
Parameters
$tokenId : string

The CSRF token id of the protected action

Tags
throws
BadMethodCallException

when no CSRF provider was injected in the constructor

Return values
string

A CSRF token

end()

Renders the form end tag.

public end(FormView $view[, array<string|int, mixed> $variables = [] ]) : string

Example usage templates:

end($form) ?>>
Parameters
$view : FormView
$variables : array<string|int, mixed> = []

Additional variables passed to the template

Return values
string

The HTML markup

errors()

Renders the errors of the given view.

public errors(FormView $view) : string
Parameters
$view : FormView
Return values
string

The HTML markup

form()

Renders the HTML for a form.

public form(FormView $view[, array<string|int, mixed> $variables = [] ]) : string

Example usage:

<?php echo view['form']->form($form) ?>

You can pass options during the call:

<?php echo view['form']->form($form, ['attr' => ['class' => 'foo']]) ?>

<?php echo view['form']->form($form, ['separator' => '+++++']) ?>

This method is mainly intended for prototyping purposes. If you want to control the layout of a form in a more fine-grained manner, you are advised to use the other helper methods for rendering the parts of the form individually. You can also create a custom form theme to adapt the look of the form.

Parameters
$view : FormView
$variables : array<string|int, mixed> = []

Additional variables passed to the template

Return values
string

The HTML markup

getName()

{@inheritdoc}

public getName() : mixed
Return values
mixed

help()

Renders the help of the given view.

public help(FormView $view) : string
Parameters
$view : FormView
Return values
string

The HTML markup

humanize()

public humanize(mixed $text) : mixed
Parameters
$text : mixed
Return values
mixed

label()

Renders the label of the given view.

public label(FormView $view[, string $label = null ][, array<string|int, mixed> $variables = [] ]) : string
Parameters
$view : FormView
$label : string = null

The label

$variables : array<string|int, mixed> = []

Additional variables passed to the template

Return values
string

The HTML markup

rest()

Renders views which have not already been rendered.

public rest(FormView $view[, array<string|int, mixed> $variables = [] ]) : string
Parameters
$view : FormView
$variables : array<string|int, mixed> = []

An array of variables

Return values
string

The HTML markup

row()

Renders the entire form field "row".

public row(FormView $view[, array<string|int, mixed> $variables = [] ]) : string
Parameters
$view : FormView
$variables : array<string|int, mixed> = []

Additional variables passed to the template

Return values
string

The HTML markup

setTheme()

Sets a theme for a given view.

public setTheme(FormView $view, string|array<string|int, mixed> $themes[, bool $useDefaultThemes = true ]) : mixed

The theme format is "<Bundle>:<Controller>".

Parameters
$view : FormView
$themes : string|array<string|int, mixed>

A theme or an array of theme

$useDefaultThemes : bool = true

If true, will use default themes defined in the renderer

Return values
mixed

start()

Renders the form start tag.

public start(FormView $view[, array<string|int, mixed> $variables = [] ]) : string

Example usage templates:

start($form) ?>>
Parameters
$view : FormView
$variables : array<string|int, mixed> = []

Additional variables passed to the template

Return values
string

The HTML markup

widget()

Renders the HTML for a given view.

public widget(FormView $view[, array<string|int, mixed> $variables = [] ]) : string

Example usage:

<?php echo $view['form']->widget($form) ?>

You can pass options during the call:

<?php echo $view['form']->widget($form, ['attr' => ['class' => 'foo']]) ?>

<?php echo $view['form']->widget($form, ['separator' => '+++++']) ?>
Parameters
$view : FormView
$variables : array<string|int, mixed> = []

Additional variables passed to the template

Return values
string

The HTML markup

Search results