Process Submit Data with a WordPress Hook – WS Form

Process Submit Data with a WordPress Hook

You can use the ‘Run WordPress Hook’ action in combination with some simple code to intercept submission data and use it in your own PHP scripts.

To do this:

  1. Add a Run WordPress Hook action to your form. Add it as a filter.
  2. Enter the hook tag, e.g. wsf_action_filter_tag
  3. In your functions.php file, add the following code:
// Action filter hook
add_filter('wsf_action_filter_tag', 'wsf_action_function', 10, 2);

// Action function
function wsf_action_function($form, $submit) {

        // Get submit value for field ID 13685
        $my_field_value = wsf_submit_get_value($submit, 'field_123');

        // Do something with $my_field_value
        // ...

When the filter is fired, the form and submit data are passed to it.

wsf_submit_get_value accepts two parameters. You pass the submit data as the first parameter and the meta key (e.g. field_123) you wish to obtain from the submission as the second parameter.

You would change field_123 to match the field ID on your form. For example, if the field you want to obtain has an ID of 321 in the WS Form layout editor, you would use field_321 as the second parameter in the wsf_submit_get_value function. In the example above $my_field_value would then contain the value of that field and you can then use that variable for your own code.