Sending form data to another script

In this guide we will show you to how send the form data to another script, while maintaining the form validation and success actions of the Quform plugin.

Sending all form data

Add the following code to the theme functions.php file (or create a plugin for it).

123
4
5
6
7
add_action('quform_post_process_1', function (array $result, Quform_Form $form) {    wp_remote_post('http://www.example.com/script.php', array(        'body' => $form->getValues()
    ));
 
    return $result;
}, 10, 2);
add_action('quform_post_process_1', function (array $result, Quform_Form $form) {
    wp_remote_post('http://www.example.com/script.php', array(
        'body' => $form->getValues()
    ));

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 2, change the URL to the other script URL
1
2
34
5
6
7
8
9
function my_post_process(array $result, Quform_Form $form)
{
    wp_remote_post('http://www.example.com/script.php', array(        'body' => $form->getValues()
    ));
 
    return $result;
}
add_action('quform_post_process_1', 'my_post_process', 10, 2);
function my_post_process(array $result, Quform_Form $form)
{
    wp_remote_post('http://www.example.com/script.php', array(
        'body' => $form->getValues()
    ));

    return $result;
}
add_action('quform_post_process_1', 'my_post_process', 10, 2);
  • On line 3, change the URL to the other script URL
  • On line 9, replace the number 1 with the form ID

Rewriting the variable names

If the other script is expecting the values in the post data to have different names, you can rewrite them before sending the data.

Add the following code to the theme functions.php file (or create a plugin for it).

12
34567
8
910
11
12
13
14
add_action('quform_post_process_1', function (array $result, Quform_Form $form){    $data = array(
        'name' => $form->getValue('quform_1_3'),        'email' => $form->getValue('quform_1_4'),        'phone' => $form->getValue('quform_1_5'),        'message' => $form->getValue('quform_1_6')    );
 
    wp_remote_post('http://www.example.com/script.php', array(        'body' => $data
    ));
    
    return $result;
}, 10, 2);
add_action('quform_post_process_1', function (array $result, Quform_Form $form){
    $data = array(
        'name' => $form->getValue('quform_1_3'),
        'email' => $form->getValue('quform_1_4'),
        'phone' => $form->getValue('quform_1_5'),
        'message' => $form->getValue('quform_1_6')
    );

    wp_remote_post('http://www.example.com/script.php', array(
        'body' => $data
    ));
    
    return $result;
}, 10, 2);
  • On line 1, change the number 1 to the form ID
  • On lines 3 to 6, change the array so that the key is the name of the post variable the other script is expecting and replace 1_3, 1_4, 1_5 and 1_6 with the element unique ID of the elements to get the value from
  • On line 9, change the URL to the other script URL
1
2
3
45678
9
1011
12
13
14
15
16
function my_post_to_another_script(array $result, Quform_Form $form)
{
    $data = array(
        'name' => $form->getValue('quform_1_3'),        'email' => $form->getValue('quform_1_4'),        'phone' => $form->getValue('quform_1_5'),        'message' => $form->getValue('quform_1_6')    );
 
    wp_remote_post('http://www.example.com/script.php', array(        'body' => $data
    ));
    
    return $result;
}
add_action('quform_post_process_1', 'my_post_to_another_script', 10, 2);
function my_post_to_another_script(array $result, Quform_Form $form)
{
    $data = array(
        'name' => $form->getValue('quform_1_3'),
        'email' => $form->getValue('quform_1_4'),
        'phone' => $form->getValue('quform_1_5'),
        'message' => $form->getValue('quform_1_6')
    );

    wp_remote_post('http://www.example.com/script.php', array(
        'body' => $data
    ));
    
    return $result;
}
add_action('quform_post_process_1', 'my_post_to_another_script', 10, 2);
  • On lines 4 to 7, change the array so that the key is the name of the post variable the other script is expecting and replace 1_3, 1_4, 1_5 and 1_6 with the element unique ID of the elements to get the value from
  • On line 10, change the URL to the other script URL
  • On line 16, change the number 1 to the form ID

Troubleshooting

To debug the request, you can temporarily install the plugin Log HTTP Requests. Once that plugin is installed and active, test the form submission again, then go to Tools → Log HTTP Requests. Find the request to the other script URL and click into it, look at the Response section to see if there is an error message, and check the Request body to make sure the data is being sent as expected.

See also

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy