class FormHelper extends Helper
FormHelper provides helpers to help display forms.
| protected | $charset | from Helper |
| setCharset(string $charset) Sets the default charset. | from Helper | |
| string | getCharset() Gets the default charset. | from Helper |
| __construct(FormRendererInterface $renderer) | ||
| string | getName() Returns the canonical name of this helper. | |
| setTheme(FormView $view, string|array $themes, bool $useDefaultThemes = true) Sets a theme for a given view. | ||
| string | form(FormView $view, array $variables = array()) Renders the HTML for a form. | |
| string | start(FormView $view, array $variables = array()) Renders the form start tag. | |
| string | end(FormView $view, array $variables = array()) Renders the form end tag. | |
| string | widget(FormView $view, array $variables = array()) Renders the HTML for a given view. | |
| string | row(FormView $view, array $variables = array()) Renders the entire form field "row". | |
| string | label(FormView $view, string $label = null, array $variables = array()) Renders the label of the given view. | |
| string | help(FormView $view) Renders the help of the given view. | |
| string | errors(FormView $view) Renders the errors of the given view. | |
| string | rest(FormView $view, array $variables = array()) Renders views which have not already been rendered. | |
| string | block(FormView $view, string $blockName, array $variables = array()) Renders a block of the template. | |
| string | csrfToken(string $tokenId) Returns a CSRF token. | |
| humanize($text) | ||
| formEncodeCurrency($text, $widget = '') |
Sets the default charset.
| string | $charset | The charset |
Gets the default charset.
| string | The default charset |
| FormRendererInterface | $renderer |
Returns the canonical name of this helper.
| string | The canonical name |
Sets a theme for a given view.
The theme format is "
| FormView | $view | A FormView instance |
| string|array | $themes | A theme or an array of theme |
| bool | $useDefaultThemes | If true, will use default themes defined in the renderer |
Renders the HTML for a form.
Example usage:
<?php echo view['form']->form($form) ?>
You can pass options during the call:
<?php echo view['form']->form($form, array('attr' => array('class' => 'foo'))) ?>
<?php echo view['form']->form($form, array('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.
| FormView | $view | The view for which to render the form |
| array | $variables | Additional variables passed to the template |
| string | The HTML markup |
Renders the form start tag.
Example usage templates:
<?php echo $view['form']->start($form) ?>>
| FormView | $view | The view for which to render the start tag |
| array | $variables | Additional variables passed to the template |
| string | The HTML markup |
Renders the form end tag.
Example usage templates:
<?php echo $view['form']->end($form) ?>>
| FormView | $view | The view for which to render the end tag |
| array | $variables | Additional variables passed to the template |
| string | The HTML markup |
Renders the HTML for a given view.
Example usage:
<?php echo $view['form']->widget($form) ?>
You can pass options during the call:
<?php echo $view['form']->widget($form, array('attr' => array('class' => 'foo'))) ?>
<?php echo $view['form']->widget($form, array('separator' => '+++++')) ?>
| FormView | $view | The view for which to render the widget |
| array | $variables | Additional variables passed to the template |
| string | The HTML markup |
Renders the entire form field "row".
| FormView | $view | The view for which to render the row |
| array | $variables | Additional variables passed to the template |
| string | The HTML markup |
Renders the label of the given view.
| FormView | $view | The view for which to render the label |
| string | $label | The label |
| array | $variables | Additional variables passed to the template |
| string | The HTML markup |
Renders the help of the given view.
| FormView | $view | The parent view |
| string | The HTML markup |
Renders the errors of the given view.
| FormView | $view |
| string | The HTML markup |
Renders views which have not already been rendered.
| FormView | $view | The parent view |
| array | $variables | An array of variables |
| string | The HTML markup |
Renders a block of the template.
| FormView | $view | The view for determining the used themes |
| string | $blockName | The name of the block to render |
| array | $variables | The variable to pass to the template |
| string | The HTML markup |
Returns a CSRF token.
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.');
}
| string | $tokenId | The CSRF token id of the protected action |
| string | A CSRF token |
| BadMethodCallException | when no CSRF provider was injected in the constructor |
| $text |
| $text | ||
| $widget |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.html