Home  ›  AJAX Form Pro: + Admin Panel & Database  ›  How to Show Custom Content After the Form is Submitted

How to Show Custom Content After the Form is Submitted

After you submit a form, by default, AJAX Form Pro will show a confirmation message (that is set in the form’s configuration page: Notifications > “Success Output HTML Code”) like the one from the image below:

Default Message: After Successful Submit

You can, however, customize this output as you want by creating an output template that will be loaded after form submit. For security reasons and due to the fact that this option is mostly used by advanced developers, the template should be created in .PHP and uploaded into the directory “/ajax-form-app/templates/after-success-submit-output/”. It is preferable to name the template similar with the form’s title for easier reference when you will access it later.

For example, you’ve upload a file called “my-contact-form-title.php” (full path: /ajax-form-app/templates/after-success-submit-output/my-contact-form-title.php). You will see it populated in the Notifications section of the Form’s Settings like this:

Form's Settings: After Successful Submit Show Output

After you select it, make sure you press “Update Form Configuration” to save the changes.

Now, you can add any content you want there, make connection to the database, output it. The condition is to have the variable $status_output declared with your content.

Here’s an example of what “my-contact-form-title.php” might contain (this example shows the fields that were submitted in the order you arranged them in the Admin Panel):

<?php
// This file should not be accessed directly as it's relevant only in conjunction with the script
if( ! isset($path_to_custom_output) ) { exit('You can not access this file directly.'); }
 
$status_output = '<div class="afb_notification_ok">'.$afp_conf['notifications']['message_sent_s'].'</div>'."\n";
 
$status_output .= "<div style='margin: 0 0 10px 0;'>This is extra content shown after the form is sent. It can be modified as you wish. The following fields were submitted:</div>";
 
$status_output .= '<table>';
 
$all_fields_row = array();
 
$pos = count($_parse_post)   1;

foreach($_parse_post as $afb_p_key => $afb_p_value) {
        $afb_p_key = str_replace('[]','', $afb_p_key);
 
        if(isSet($afb_form_fields[$afb_p_key]['text']) && $afb_form_fields[$afb_p_key]['text'] != '') {
 
        if($afb_form_fields[$afb_p_key]['position'] > 0) { 
            $field_position = $afb_form_fields[$afb_p_key]['position'];
        } else {
            $field_position = $pos;
        }
 
        $all_fields_row[$field_position] = '<tr><td valign="top"><strong>'.$afb_form_fields[$afb_p_key]['text'].":</strong>&nbsp;&nbsp;</td><td>".nl2br($afb_replacements['{'.$afb_p_key.'}'])."</td></tr>";
 
        $pos  ;
    }
}
 
ksort($all_fields_row);
 
foreach($all_fields_row as $afr) {
    $status_output .= $afr;
}
 
$status_output .= "</table><br />";
?>
The template is included in parse.php (at the end of the file) where all the variables you see in the code are already set.

Don’t get intimidated by the example shown above 😉 as you’re free to create your own and edit it as you wish, just make sure $status_output is declared with the actual output that will be shown after the form is submitted successfully.

If you want, you can use this example to show the visitor a confirmation of successful submit with the values that were sent.


4 Responses to “How to Show Custom Content After the Form is Submitted”

  1. Hi,
    for me – I don’t get it.
    This solution is a bit to advanced …

    … 🙁

    • admin says:

      I made it this way so that you have total flexibility in the output that is returned. If you don’t feel comfortable editing PHP code, then deselect any template, and only edit “Success Output HTML Code”. You can put there any HTML code you want 😉

  2. martin says:

    is it possible to output placeholders (like the name), too?
    i want to output something linke “thank you {sender_name}”…

    • admin says:

      Yes, definitely. The value is inside $_parse_post array. If the name of the field is “first_name” it will be accessed via $_parse_post[‘first_name’]. If the field doesn’t have any name and a name was assigned automatically (since you need an input name on every form element), then the name will be $_parse_post[‘fID_HERE’]; – Replace ID_HERE with the actual field ID number that you see when you view the field list of the form (Manage Form’s Fields Page).

Leave a Reply

Help us improve the wiki Send Your Comments

Optimization WordPress Plugins & Solutions by W3 EDGE