Form validation in PHP

To validate a form, create identical object that you have used to generate form's HTML and then use$form->validate($postedData) method. Each field can have many validation rules, which can be added using addValidator() method on each field.

<?php
....
$field->addValidator('Required');

See validators page for a full list of available validators. If a validator requires attributes, pass an array where first element is a validator name and second element contains specific validation parameters.

<?php
$field->addValidator(
array(
'Regex',
'/^[a-zA-Z0-9]*$/'
)
)

Bellow is a sample code that validates submitted data. Put this code into your controller.

Prevent spam

Each newly created form by default adds antispam field which tries to detect robots and prevents them from submitting the form. You can remove this field using $form->removeSpamCheck() method.

CSRF check

Also, by default, each newly created form adds security field to check against CSRF attack. It is just a simple hidden input field with security token value in it. All POST methods to controller have to have this value set or ImpressPages will reject the request as an attack. If for some reason you don't need that field in the form, use $form->removeCsrfCheck() method to remove it.