Passing data from one form to another

This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.

In this guide we will have a small form to gather some data from the user then when the user submits the form they are redirected to a second larger form with the previously submitted data already populated.

Step 1

Create the first form. In this example we’ve created a form with a Dropdown Menu where the user selects a Package and two Date elements where they choose a Check In and Check Out date. While editing this form go to Settings → General → Successful submit options and at On successful submit choose Redirect to another page. At the Redirect to option choose URL and leave the field blank (we will set this in Step 2).

Step 2

In this step we will add some PHP code to set the redirect URL and add the submitted data to it. Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

1
2
3
4567
8
9
10
1112
13
14
15
function my_form_redirect($url, $form)
{
    $data = array(
        'package' => $form->getValue('iphorm_1_1'),        'checkin' => date('j,n,Y', strtotime($form->getValuePlain('iphorm_1_2'))),        'checkout' => date('j,n,Y', strtotime($form->getValuePlain('iphorm_1_3')))    );
 
    $data = array_map('rawurlencode', $data);
 
    $url = add_query_arg($data, 'http://www.example.com/form-2'); 
    return $url;
}
add_action('iphorm_success_redirect_url_1', 'my_form_redirect', 10, 2);
function my_form_redirect($url, $form)
{
    $data = array(
        'package' => $form->getValue('iphorm_1_1'),
        'checkin' => date('j,n,Y', strtotime($form->getValuePlain('iphorm_1_2'))),
        'checkout' => date('j,n,Y', strtotime($form->getValuePlain('iphorm_1_3')))
    );

    $data = array_map('rawurlencode', $data);

    $url = add_query_arg($data, 'http://www.example.com/form-2');

    return $url;
}
add_action('iphorm_success_redirect_url_1', 'my_form_redirect', 10, 2);
  • On line 4 change iphorm_1_1 to the unique ID of the Package (Dropdown Menu) element
  • On line 5 change iphorm_1_2 to the unique ID of the Check In (Date) element
  • On line 6 change iphorm_1_3 to the unique ID of the Check Out (Date) element
  • On line 11 change http://www.example.com/form-2 to the URL of the second form
  • On line 15 change the number 1 to the form ID of the first form

Step 3

Create the second form. Use the same type of fields than you used in the first form for the fields to populate, and add any further fields as needed. For each of the fields you want to populate, edit them and go to the Optional tab, then enable the Dynamic default value option. For the Parameter name field enter the string you set as the key (left side) for the $data array in Step 2. So for our example form:

  • The Package field is a Dropdown Menu so we enable Dynamic default value and enter the Parameter name package
  • The Check In field is a Date element so we enable Dynamic default value and enter the Parameter name checkin
  • The Check Out field is a Date element so we enable Dynamic default value and enter the Parameter name checkout

That’s it! Test it out by submitting the first form and see if the data ends up populated in the second form.

See also

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