Skip to content

FastForm in the Real World

One of my favorite things about Formr is the ability to save form/validation sets for reuse using FastForm. I can't even count the number of times I've had to create a registration form and all I had to type was...

$form->fastform('registration');

...and, BLAMMO! Out pops a registration form, ready to go! And then to process and validate it I just type…

$post = $form->fastpost('registration');

...and KAPOW! My registration form is now enabled for server-side validation, complete with verifying the email address and matching and hashing the password! Plus, all of my $_POSTdata is available for me in the $post variable, so if I want the username I just do...

$username = $post['username'];

In fact, this is pretty much what my registration forms now look like from a PHP standpoint.

<?php
    require 'vendor/autoload.php';
    $form = new Formr\Formr('bootstrap');

    if ($form->submitted())
    {
        $form->required = '*';
        $post = $form->fastpost('registration');

        if (!$form->errors()) {
            $session->process_registration($post);
        }
    }

    $form->messages();
    $form->fastform('registration');
?>

Seriously, can it not get any easier than that? I do the exact same thing for a login form and a contact form. This alone saves me hours, if not days, in development time.

The FastForms are readily available in lib/class.forms.php, and if I want to modify them I just copy one and paste it into my_classes/my.forms.php, give it a new name and enter that as the FastForm argument; it's now ready and willing any time I need it.

Check out the Formr Extend repo for more information on creating and saving your own FastForms!