Scripts
The Scripts tab of a form runs your own PHP or JavaScript at fixed moments. It is meant for developers. A mistake in a PHP script can break the form or the whole page, so test on a copy of your site first.
Write PHP without the <?php tag. The code runs with the rights of your website, so only give access to the form editor to people you trust, see Permissions.
PHP Processing
| Script | When it runs | What you can use |
|---|---|---|
| Script called before form is generated | Before the placeholders of the layout are replaced. | $formLayout, and $val to pre-fill fields: $val['Name'] = 'John'; |
| Script called on form display | When the form is shown. | $formLayout, the HTML of the form. |
| Script called before form is validated | Before the answers are checked. | The posted values in $_POST['form']. |
| Script called on form process | When the form is processed. | $_POST['form'], $invalid (the list of fields that failed), $isAjax. |
| Script called after form has been processed | After the submission is saved. | $thankYouMessage. |
PHP Email
| Script | What you can use |
|---|---|
| Script called before the User Email is sent. | $userEmail, the array with the recipient, subject, text and attachments. |
| Script called before the Admin Email is sent. | $adminEmail. |
| Script called before the Additional Emails are sent. | $additionalEmail. |
For example, to send the admin email to a different address depending on an answer:
if ($_POST['form']['Department'][0] == 'sales') {
$adminEmail['to'] = '[email protected]';
}
Javascript
JavaScript for this form, with the <script> tags. It is added to the page with the form.
Directory scripts
A directory has its own PHP scripts for the listing and details pages and its emails.