Hooks for Developers
FormGlut has PHP hooks and front-end events so you can extend it. The full reference is in the EXTENDING.md file inside the plugin folder.
Run code after every submission
formglut_entry_submitted runs after every accepted submission (not spam):
add_action( 'formglut_entry_submitted', function ( $form, $fields_data, $entry_id ) {
if ( 3 !== (int) $form->id ) {
return;
}
// $fields_data holds the answers, keyed by field ID.
error_log( 'New entry #' . $entry_id );
}, 10, 3 );
$form is the form object ($form->id, $form->title). $entry_id is 0 when the form does not save entries.
Submission hooks (in the order they run)
| Hook | Type | Use |
|---|---|---|
formglut_pre_submission | filter | Return a WP_Error to refuse a submission. |
formglut_validate_field_value | filter | Extra checks on any field. |
formglut_sanitize_field_value | filter | Change a cleaned value. |
formglut_submission_errors | filter | Checks that compare several fields. |
formglut_spam_check | filter | Return a reason to mark the entry as spam. |
formglut_submission_data | filter | Change the answers before payment and saving. |
formglut_payment_total | filter | Change the amount to charge. |
formglut_entry_data | filter | Change the row that is saved. |
formglut_entry_created | action | After the entry is saved. |
formglut_pre_send_notifications | filter | Return true to send the notifications yourself. |
formglut_notification_email | filter | Change an email (to, subject, body, headers, attachments). |
formglut_entry_submitted | action | After an accepted submission. |
formglut_submission_response | filter | Change the reply sent to the browser. |
formglut_replace_tags | filter | Add your own smart tags. |
Form output hooks
| Hook | Type | Use |
|---|---|---|
formglut_form_availability | filter | Close a form with your own reason and message. |
formglut_form_attributes | filter | Add attributes to the <form> tag. |
formglut_form_fields_before / formglut_form_fields_after | action | Print output inside the form. |
formglut_form_html | filter | Change the whole form HTML. |
formglut_field_config | filter | Change a field before it is drawn and checked, for example dynamic choices. |
formglut_display_value | filter | Change how a value is shown in emails, tags, exports and the entry screen. |
Forms and entries
| Hook | Use |
|---|---|
formglut_form_created, formglut_before_form_update, formglut_before_form_delete | React to form changes. |
formglut_before_entry_delete, formglut_before_entry_status_change | React to entry changes. |
formglut_disposable_email_domains | Add or remove throwaway email domains. |
formglut_currencies | Add currencies. |
formglut_capability | Change the capability needed for FormGlut screens. |
Form templates
Templates are read only when someone opens the template picker. Each template lists only what differs from the field type’s defaults; choices need only a label.
| Hook | Use |
|---|---|
formglut_templates | Filter. Add templates to the picker. To load a folder of template files: FormGlut_Templates::load_dir( $dir, 'my-plugin' ). |
formglut_template_categories | Filter. Add categories (slug => label). |
Give a field 'ref' => 'name' and write {ref:name} in a settings text to insert that field’s value. icon is a Font Awesome icon name.
add_filter( 'formglut_templates', function ( $templates ) {
$templates[] = array(
'slug' => 'my_booking',
'title' => 'My booking form',
'description' => 'Name, email and a date.',
'icon' => 'faCalendarDays',
'category' => 'events',
'fields' => array(
array( 'type' => 'name' ),
array( 'type' => 'email', 'label' => 'Email', 'required' => true ),
array( 'type' => 'date', 'label' => 'Date', 'ref' => 'date' ),
),
'settings' => array(
'confirmation' => array( 'message' => 'See you on {ref:date}!' ),
),
);
return $templates;
} );
Front-end events
Events fire on the form element and bubble up:
| Event | Detail |
|---|---|
formglut:init | { formId, form } |
formglut:before-submit | { formId, form, formData }. Cancelable. Add values to formData. |
formglut:submitted | { formId, entryId, response } |
Example: track a conversion.
document.addEventListener( 'formglut:submitted', function ( e ) {
if ( window.gtag ) {
gtag( 'event', 'generate_lead', { form_id: e.detail.formId } );
}
} );
For a single form, you can also use Settings › Layout & CSS › JavaScript after submit.
