PHP Scripts - Pre-Processing

Further extending your form's custom functionality for cases where the default PHP Scripts areas couldn't cover.

The PHP Scripts - Pre-Processing area has 2 different PHP sections, that are triggered before certain events as follows.

Script called before form is generated

The scripts added in this area are executed before your form is actually generated. The $formLayout variable is provided where you'll find your form's HTML layout along with its placeholders that haven't yet been replaced.

The main focus in this area would be the $val array, which can be used to pre-set fields in your form in a dynamic fashion (useful if you want to do this before your form is generated from one single area).

Example (replace field naming accordingly; case sensitive):

    //for single value fields like textbox or radio group:
    $val['textbox-exact-name'] = 'airplane';

    //for multiple value fields like a checkbox or multi-selection dropdown (this assumes your field already has these items):
    $val['myCheckboxName'][]='car';
    $val['myCheckboxName'][]='ship';
    $val['myCheckboxName'][]='submarine';

    //for the specialized BirthDay form element:
    $val['bday-field-name']['d']='03';
    $val['bday-field-name']['m']='06';
    $val['bday-field-name']['y']='1999';
Script called before form is validated

Your form data can be modified here, before validations are run (this is applied even when using the AJAX validation in your form). Useful if you want to adjust field values before these are further validated. By default, form data can be returned from $_POST['form']. Example (whereas total, field1 and field2 are the exact given names of the form fields in question; case sensitive):

    $_POST['form']['total'] = $_POST['form']['field1'] + $_POST['form']['field2'];
    //in this case, the total adjustment will be done before the field validation is performed.

12 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that