DeveloperTutorials for Web Developers & DesignersForms

Advanced E-mail Notifications

This form will ask the user "What can we help you with?", and send a notification message to an e-mail address depending on which item is selected.

This tutorial will extend on the tutorial that covers basic contact enquiry forms, to show how server code can be used to change the form notification email address based on fields selected by the user.

The Form

To get started, add the following form to the page (edit page, open src view, paste):


The <ss:forms:combobox> control on line 10 allows the user to select between a range of options for "What can we help you with?". Click here to read more about the combobox control.

The combobox can be referenced by it's ID form_reason, and contains the available options.

Passing Fields to Server Code

Instead of specifying an e-mail address in the onsubmitemail attribute of the form, a custom function has been referenced instead. A custom PHP function "getEmailAddress()" will be setup, to return the correct e-mail address based on the value of the combobox.

The custom function needs the value of the comobox, which can be provided by using $form_reason.getValue().

In cases where you need to send more than one field, use $my_form.getValues() to return all form fields (read more here). 

The Server Code

Custom PHP functions are usuallly added via the PHP tab, located in the src view when editing a page. Where PHP functions need to be used accross multiple pages or forms, the function would be added to the website design instead.

Add the following PHP code to the page (edit the page, open src view, click the PHP tab, and paste):