DeveloperTutorials for Web Developers & DesignersForms

Calling Custom PHP Functions

The OnSubmitServer Attribute

The onSubmitServer attribute is added to the <forms:form> control, to call a custom PHP function to be run on submission of the form: 

<forms:form id="my_form" onsubmitserver="myFunction()"> <forms:row label="Field 1"> <forms:editbox id="field_1" /> </forms:row> <forms:row label="Field 2"> <forms:editbox id="field_2" /> </forms:row> <forms:row type="one_column" align="center"> <forms:submitbutton value="Submit" /> </forms:row> </forms:form>


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

Process Form Values with getValues()

The getValues() function can be used to pass form fields to your PHP function. The getValues() function returns an array of all form items, keyed by form item ids or names:


HTML:

<forms:form id="my_form" onsubmitserver="myFunction($my_form.getValues())"> <forms:row label="Field 1"> <forms:editbox id="field_1" /> </forms:row> <forms:row label="Field 2"> <forms:editbox id="field_2" /> </forms:row> <forms:row type="one_column" align="center"> <forms:submitbutton value="Submit" /> </forms:row> </forms:form>


PHP:

<?php function myFunction($arrSubmission) { varDump($arrSubmission); die(); } ?>

getValuesForComponent()

As an alternative to the above getValues() function, the getValuesForComponent() function returns an array of all form items, keyed by the datacolumn attribute.

<forms:editbox id="field_1" datacolumn="field_1" />