Display submitted form data after redirecting to another page

The submitted form data will be lost after redirecting, so we’ll use PHP sessions to save the data so that we can access it on the next page.

Step 1

Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

1
2
34
5
function my_save_form_data($form)
{
    $_SESSION['iphorm_2'] = $form;}
add_action('iphorm_post_process_2', 'my_save_form_data');
function my_save_form_data($form)
{
    $_SESSION['iphorm_2'] = $form;
}
add_action('iphorm_post_process_2', 'my_save_form_data');
  • On lines 3 and 5, change the number 2 to your form ID

Step 2

We need to execute PHP code to print the saved variables on the page we redirect to. One way to do this is to create a shortcode to display the form data. For example, add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

12
3
4
567
89
10
11
12
13141516
17
18
19
20
21
22
23
24
function my_display_form_data_2(){
    $output = '';
 
    if (class_exists('iPhorm') && isset($_SESSION['iphorm_2']) && $_SESSION['iphorm_2'] instanceof iPhorm) {        $form = $_SESSION['iphorm_2']; 
        $output .= '<h2>Thanks, ' . $form->getValueHtml('iphorm_2_1') . '!</h2>';        $output .= '<h3>Your submission has been sent.</h3>';
 
        $output .= '<table>';
 
        $output .= '<tr><td>Name</td><td>' . $form->getValueHtml('iphorm_2_1') . '</td></tr>';        $output .= '<tr><td>Email</td><td>' . $form->getValueHtml('iphorm_2_2') . '</td></tr>';        $output .= '<tr><td>Message</td><td>' . $form->getValueHtml('iphorm_2_3') . '</td></tr>'; 
        $output .= '</table>';
    } else {
        $output .= 'Form data not found.';
    }
 
    return $output;
}
add_shortcode('my_display_form_data_2', 'my_display_form_data_2');
function my_display_form_data_2()
{
    $output = '';

    if (class_exists('iPhorm') && isset($_SESSION['iphorm_2']) && $_SESSION['iphorm_2'] instanceof iPhorm) {
        $form = $_SESSION['iphorm_2'];

        $output .= '<h2>Thanks, ' . $form->getValueHtml('iphorm_2_1') . '!</h2>';
        $output .= '<h3>Your submission has been sent.</h3>';

        $output .= '<table>';

        $output .= '<tr><td>Name</td><td>' . $form->getValueHtml('iphorm_2_1') . '</td></tr>';
        $output .= '<tr><td>Email</td><td>' . $form->getValueHtml('iphorm_2_2') . '</td></tr>';
        $output .= '<tr><td>Message</td><td>' . $form->getValueHtml('iphorm_2_3') . '</td></tr>';

        $output .= '</table>';
    } else {
        $output .= 'Form data not found.';
    }

    return $output;
}
add_shortcode('my_display_form_data_2', 'my_display_form_data_2');
  • On lines 1, 5, 6 and 24 replace the number 2 with the form ID.
  • On lines 8, 13 , 14 and 15 replace iphorm_2_1, iphorm_2_2, iphorm_2_3 and iphorm_2_4 with the unique element ID of the elements that you want to print the value for. To add additional data to the table just duplicate line 13 and change the label and unique element ID.

Step 3

Create a page within WordPress (or use an existing one), and this shortcode into the page content:

[my_display_form_data_2]

Set up the form to redirect to this page by going to Form Builder → Settings → General → Successful submit options, at On successful submit choose Redirect to another page, at Redirect to choose Page and select the destination page that contains the shortcode.

Still having trouble? Head over to the forums.

Forums