ValidForm Builder

Easy and safe XHTML 1.0 strict forms with client and server-side validation!

View on GitHub

ValidForm Builder

The ValidForm Builder is a PHP and JavaScript library that simplifies the often tedious creation of standards based web forms. Correct field validation of forms is an often overlooked problem and can lead to serious security issues. Building a form and adding validation to it was never that easy.

Why use ValidForm Builder?

Documentation

The documentation still isn’t as complete as we’d like it to be but it should enable you to get started with the essential basics of ValidForm Builder.

If you have any questions, please ask them on StackOverflow.com and be sure to tag your question with the ‘validform’ tag. We regulary monitor these questions and try to answer them as soon as we can :)

Get started with Conditions and Comparisons

This feature is as new as it is powerful. Since ValidForm Builder 2.0 public beta (that’s what we called it back then), one of the many new awesome features are conditional fields. Here’s a quick preview on how they work:

1) Create two regular fields

$objFirstName = $objForm->addField(
    "name", 
    "Your name", 
    VFORM_STRING, 
    [
        "required" => true
    ], 
    [
        "required" => "This field is required"
    ]
);

$objLastName = $objForm->addField(
    "lastname", 
    "Last name", 
    VFORM_STRING, 
    [
        "required" => true // not required for robin ;-)
    ], 
    [
        "required" => "This field is required"
    ]
);

2) Now, add a condition to the lastname field. For example, we want it to become optional when name is Robin. After all, we all know that Robin’s last name is ‘Hood’. So the way we’ll write that out in plain text would be: lastname-field’s property required will become false when name-field’s value will be Robin. Here’s how the condition will look in PHP:

$objLastName->addCondition(
    "required", 
    false, 
    [
        new VF_Comparison(
            $objFirstName, 
            VFORM_COMPARISON_EQUAL, 
            "robin" // Comparison values are case insensitive.
         )
    ], 
    VFORM_MATCH_ANY
);

3) When you run this example and type in ‘Robin’ in the name field, last name will become optional. As always with ValidForm Builder: this validates both client-side and server-side!

For more information you’ll just have to dig in the code for now. More than ever we added comments and PHPDoc blocks to all the code we’ve been working on. This release is for those who don’t need to RTFM.

Happy coding!

Felix & Robin