Skip to content

Extending WordPress WP Forms Plugin functionality

WP Forms plugin is a great form plugin that bundles a friendly and useful visual form builder. As a developer i want to use the form builder editor to allow users be independent creating the forms but i also want to save the form submission in it’s own database structure, therefore did a little research on the plugin code and found a neat way to do this.

I will try to share, as clearer as possible, the steps you need to do so that you can access form submission data without the need to change the actually plugin. This can be done either by adding the extension into your theme or building a small plugin for it.

WP Forms hook on form submission process

WP Forms executes the hook wpforms_process_complete on the form submission process therefore by hooking into this action you’ll be able to grab form fields and values so that you can work your way.

The snippet from WP Forms code where it executes the action:

do_action( 'wpforms_process_complete', $this->fields, $entry, $form_data, $entry_id );

How to grab a form submitted information using this action

In order to hook this action we just need to use the WordPress add_action function.

add_action("wpforms_process_complete", 'function_save_custom_form_data');

You can see that i am attaching the function function_save_custom_form_data to the action wpforms_process_complete, our last step is just to define the function.


function function_save_custom_form_data($params) {
print_r($params);
// Do whatever you need
// Can store data on a database, send to an external api, or other
return true;
}

The function receives an array as input, the array on WP Forms will have the following structure.

An array of fields, ordered by form position each of them containing the following data:

  • name => Name of the field
  • value => Value of the field
  • id => Id of the field
  • type => Type of the field (text, textarea, … )

 

 

 

 

 

 

 

There are many hooks you can attach actions to inside WP Forms, this seems the more needed one, hope you liked it and that helps in any of your projects.

You can get WP Forms on their website or install the Lite plugin as any other WordPress plugin.

Published inwordpress

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *