Processing form submissions
After a form has been submitted the field values need to be processed. The plugin comes with the ability to automatically save form data to entries and to send custom emails. Emails and entries can be configured in the form settings but are not enabled by default.
If you need to process the form data further the handy action hook
af/form/submission should be used. The hook can be used in three different ways.
The first hook is invoked for all form submissions while the two last ones allow you to specify a form using either the form post ID or form key. It’s recommended to use the form key.
The action passes three different parameters:
$form– The form object
$fields– Array of the submitted fields and their processed values
$args– Array of arguments used to display the form
To simplify the retrieval of field values a helper function
af_get_field is provided which takes the field name/key to find. The function returns a processed value in the same format as ACF’s
The following is an example of processing a form submission and extracting the value entered into the field with name “email”.
af_get_field required you to pass the
$field array as a second parameter. As of AF 1.1 this is no longer required or recommended.