Form component for shadowprince/slimext

0.2.3 2013-11-19 14:00 UTC

This package is not auto-updated.

Last update: 2024-12-17 02:28:22 UTC


README

Forman is library for working with forms.

in code

$form = new \Forman\Form(
    new \Forman\Field\Value("email"),
    new \Forman\Field\Text("text"),
    (new \Forman\Field\Checkbox("subscr"))->setValue(1)
);

if ($data = $form->process($_POST)) {
    // send email
}

render_template("contact.html", array(
    "form" => $form->getRenderer("\Forman\Render\HTML\Renderer")
        ->setAction("/contact")
        ->GET(),
));

in template

{{ form.render|raw }}

or

{{ form.top|raw }}
That's my form
{{ form.elements|raw }}
{{ form.bottom|raw }}

or even

<form action="{{ form.getAction }}" method="POST">
    {% for field in form.getFields %}
        {% if field.getCaption %}
            <label class="caption">{{ field.getCaption }}</label>
        {% endif %}
        <span class="field">
            {{ field.renderTag|raw }}
        </span>
        {% if field.getHint %}
            <span class="hint">
                {{ field.getHint }}
            </span>
        {% endif %}
    {% endfor %}
</form>

Forman writed for slimext, but not attached to it, you can use it with any framework or without it. Additional parameters to process passed to form validators (you can provide orm object or application instance).