Templating\Helper\FormHelper (Bundle\FrameworkBundle)
Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper
class FormHelper extends Helper
FormHelper provides helpers to help display forms.
Methods
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) 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 | 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) |
Details
public setCharset(string $charset)
Sets the default charset.
public string getCharset()
Gets the default charset.
public __construct(FormRendererInterface $renderer)
public string getName()
Returns the canonical name of this helper.
public setTheme(FormView $view, string|array $themes)
Sets a theme for a given view.
The theme format is "
public string form(FormView $view, array $variables = array())
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.
public string start(FormView $view, array $variables = array())
Renders the form start tag.
Example usage templates:
<?php echo $view['form']->start($form) ?>>
public string end(FormView $view, array $variables = array())
Renders the form end tag.
Example usage templates:
<?php echo $view['form']->end($form) ?>>
public string widget(FormView $view, array $variables = array())
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' => '+++++')) ?>
public string row(FormView $view, array $variables = array())
Renders the entire form field "row".
public string label(FormView $view, string $label = null, array $variables = array())
Renders the label of the given view.
public string errors(FormView $view)
Renders the errors of the given view.
public string rest(FormView $view, array $variables = array())
Renders views which have not already been rendered.
public string block(FormView $view, string $blockName, array $variables = array())
Renders a block of the template.
public string csrfToken(string $tokenId)
Returns a CSRF token.
Use this helper for CSRF protection without the overhead of creating a form.
echo $view['form']->csrfToken('rmuser'.$user->getId());
Check the token in your action using the same CSRF token id.
$csrfProvider = $this->get('security.csrf.tokengenerator');
if (!$csrfProvider->isCsrfTokenValid('rmuser_'.$user->getId(), $token)) {
throw new \RuntimeException('CSRF attack detected.');
}
public humanize($text)
© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/3.0/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.html