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. By using a WordPress filter you can return the submit object back to WS Form for use in other actions.

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_filter_tag.
  3. Set the Priority setting to ‘Before other actions’.
  4. Click ‘Save & Close’.
  5. In your functions.php file, add the following code:
// Add filter
add_filter('wsf_filter_tag', 'wsf_filter_function', 10, 2);

// Filter function
function wsf_filter_function($form, $submit) {

    // Set meta key for field ID 123 (Change this to your field ID)
    $meta_key = 'field_123';

    // Get value submit object
    $field_value_old = $submit->meta[$meta_key]['value'];

    // Do something with $field_value_old (This is just an example)
    $field_value_new = str_replace('replace_this', 'with_this', $field_value_old);

    // Set value in submit object
    $submit->meta[$meta_key]['value'] = $field_value_new;

    // Return the submit object back to WS Form
    return $submit;
}

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

In the example above, 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 enter field_321 as the $meta_key variable.