Skip to content

Forms

This extension provides functions for generating HTML form tags in Twig templates.

Functions

Usage

First, the extension needs to be added to Twig:

use Centum\Twig\FormExtension;
use Twig\Environment;

/** @var Environment $twig */

$twig->addExtension(
    new FormExtension()
);

Within your Twig files, you can now use these functions:

{{ form_start() }}

<input type="text" name="username">
<input type="password" name="password">

{{ form_end() }}

form_start() can also be used to specify a HTTP method and an action URL:

{{ form_start("POST", "/login") }}

<input type="text" name="username">
<input type="password" name="password">

{{ form_end() }}