Execute PHP on Form Submissions

The OnSubmitServer Attribute

The onSubmitServer attribute can be added to the <forms:form> UI control, to have the form execute a custom PHP function on submission: 

<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 usually defined within the PHP tab, located in the SRC view when editing a Page. Where you need to use the PHP function across 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" />