| FormToEmail Remote | |
| Remotely hosted contact form service | Home Register Pro Signup Login Contact Support |
|
Auto-redirect with posted form values
Pro service only As an alternative to simply redirecting to another page, or using the default "thank you" message, you can redirect to a page that can show some, all or none of the submitted form values when the form has been successfully sent. To use this option, you will need to enable it in the form configuration (for the form in question) in the User Admin Area, which you can get from the "Login" link above. The option to enable is: auto_redirect_with_post You will also need to enter the URL of the page to redirect to, in the form configuration option redirect_url. The benefit of using this redirect, is that you can display submitted form values on the page that you redirect to. To do so, the page needs to be a "dynamic" page like PHP or ASP (only PHP is supported here). You cannot show the submitted form values on a static page like an HTML page (e.g .htm, .html). The system uses an automated POST to take your visitor to the "thank you" page when they have successfully submitted your form. The submitted form values are also sent with the POST and are availabe to the resultant page. Displaying the submitted form values If you are new to working with PHP code, have a look at the "Editing PHP code" item in the Support section. To display the submitted form values on the "thank you" page, you need to put some PHP code on the page. The page can consist of PHP code only, or a mix of PHP and HTML code (the latter being the norm). At a point in your page BEFORE you want to show the submitted form values, add this PHP code:
<?php
foreach(array_keys($_POST) as $key){if(!is_array($_POST[$key])){$_POST[$key] = stripslashes(urldecode($_POST[$key]));}else{foreach(array_keys($_POST[$key]) as $key2){$_POST[$key][$key2] = stripslashes(urldecode($_POST[$key][$key2]));}}} ?>Then after that, at a point in the page where you want to show a submitted form value, use this code:
<?php if(isset($_POST['form_field'])){print $_POST['form_field'];} ?>
Replace 'form_field' with the EXACT name of the field on your form. So for example, if you have an address input on your form like this:
<input type="text" name="Address">
...and you wanted to show it on the "thank you" page, you would use this code:
<?php if(isset($_POST['Address'])){print $_POST['Address'];} ?>
Dealing with array inputs You might have an array input on your form, like this:
<input type="checkbox" name="fruit[]" value="apple">Apple
<input type="checkbox" name="fruit[]" value="orange">Orange <input type="checkbox" name="fruit[]" value="banana">Banana The above code is for checkboxes that all have the same name "fruit". The square brackets after the name denotes that the input is an array. You might also have this on a multiple select input. If the name has got square brackets, it's an array. These are dealt with differently as the array can have more than one value. One way to display these is to write code for every value of the array, like this:
<?php
if(isset($_POST['fruit']) && in_array("apple",$_POST['fruit'])){print "apple<br>";}
In the above example, if all three were checked, they would appear on the "thank you" page, like this:
apple Another way to deal with array inputs is to print them using the PHP foreach() construct, which is particularly useful for arrays with a lot of values. To achieve the same output as above, use this code:
<?php if(isset($_POST['fruit'])){foreach($_POST['fruit'] as $value){print $value . "<br>";}} ?>
Example "thank you" page Here is an example of a PHP and HTML "thank you" page that will display the name, email and comments fields from these form inputs:
<input type="text" name="name">
<input type="text" name="email"> <textarea name="comments"></textarea> The "thank you" page code:
<?php
foreach(array_keys($_POST) as $key){if(!is_array($_POST[$key])){$_POST[$key] = stripslashes(urldecode($_POST[$key]));}else{foreach(array_keys($_POST[$key]) as $key2){$_POST[$key][$key2] = stripslashes(urldecode($_POST[$key][$key2]));}}} ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<body> <p>Hi <?php if(isset($_POST['name'])){print $_POST['name'];} ?>. Thank you for contacting us.</p> <p><b>The information you submitted, is shown below:</b></p> <p>
<p>Any questions, just let us know.</p> </body></html> If your visitor entered the name "Bob", the email "bob@example.com" and the comments "Can you please send me more information about Product B?", the above page would display like this:
Hi Bob. Thank you for contacting us.
The information you submitted, is shown below:
Name: Bob Any questions, just let us know. |
| © FormToEmailRemote.com 2009 - 2013 |