View Full Version : Blank form2email.php

12-09-2009, 10:48 PM

great site its helped me a lot recently but I cant seem to find an answer for this one.

I have implemented some great javascript form code that gives the impression of a form over multiple pages... but on submission the filled in data seems to dissappear.... feel free to try it yourself.

www.mtsgroup.co.uk/multiPageForm.htm (http://www.mtsgroup.co.uk/multiPageForm.htm)

If I replace the action="FormtoEmail.php" command with action="javascript:void(0)" onSubmit="showValues(this)" commend the data is stored and appears in a popup box, so it is being recorded....

The code for the html is:
<title>Multi-Page Form</title>
<script language="JavaScript">
var currentLayer = 'page1';
function showLayer(lyr){
document.getElementById(lyr).style.visibility = 'visible';
currentLayer = lyr;
function hideLayer(lyr){
document.getElementById(lyr).style.visibility = 'hidden';
function showValues(form){
var values = '';
var len = form.length - 1; //Leave off Submit Button
for(i=0; i<len; i++){
if(form[i].id.indexOf("C")!=-1||form[i].id.indexOf("B")!=-1)//Skip Continue and Back Buttons
values += form[i].id;
values += ': ';
values += form[i].value;
values += '\n';
font: 10pt sans-serif;
position: absolute;
top: 10;
left: 100;
visibility: hidden;
<form id="multiForm" method="POST" action="FormToEmail.php">
<div id="page1" class="page" style="visibility:visible;">
<p>Question 1 <input type="text" id="T1" size="20"></p>
<p>Question 2 <input type="text" id="T2" size="20"></p>
<p>Question 3 <input type="text" id="T3" size="20"></p>
<p>Question 4 <input type="text" id="T4" size="20"></p>
<p>Question 5 <input type="text" id="T5" size="20"></p>
<p><input type="button" id="C1" value="Continue" onClick="showLayer('page2')"></p>
<div id="page2" class="page">
<p>Question 6 <input type="text" id="T6" size="20"></p>
<p>Question 7 <input type="text" id="T7" size="20"></p>
<p>Question 8 <input type="text" id="T8" size="20"></p>
<p>Question 9 <input type="text" id="T9" size="20"></p>
<p>Question 10 <input type="text" id="T10" size="20"></p>
<p><input type="button" id="B1" value="Go Back" onClick="showLayer('page1')"><input type="button" id="C2" value="Continue" onClick="showLayer('page3')"></p>
<div id="page3" class="page">
<p>Question 11 <input type="text" id="T11" size="20"></p>
<p>Question 12 <input type="text" id="T12" size="20"></p>
<p>Question 13 <input type="text" id="T13" size="20"></p>
<p>Question 14 <input type="text" id="T14" size="20"></p>
<p>Question 15 <input type="text" id="T15" size="20"></p>
<p><input type="button" id="B2" value="Go Back" onClick="showLayer('page2')"><input type="button" id="C3" value="Continue" onClick="showLayer('page4')"></p>
<div id="page4" class="page">
<p>Question 16 <input type="text" id="T16" size="20"></p>
<p>Question 17 <input type="text" id="T17" size="20"></p>
<p>Question 18 <input type="text" id="T18" size="20"></p>
<p>Question 19 <input type="text" id="T19" size="20"></p>
<p>Question 20 <input type="text" id="T20" size="20"></p>
<p><input type="button" id="B3" value="Go Back" onClick="showLayer('page3')"><input type="submit" value="Submit" id="submit"></p>
and the code for the php is

$my_email = "stephen.reece@mtsgroup.co.uk";

$continue = "http://ukheadhunters.com/tech/ukheadhunters/thanks.htm";
$errors = array();
// Remove $_COOKIE elements from $_REQUEST.
if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
// Check all fields for an email header.
function recursive_array_check_header($element_value)
global $set;
if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}
if($set){$errors[] = "You cannot send an email header";}
// Validate email field.
if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon - Please press the back button on your internet browser.";}
$_REQUEST['email'] = trim($_REQUEST['email']);
if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid - Please press the back button on your internet browser.";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
// Check referrer is from same site.
if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}
// Check for a blank form.

// Display any errors and exit if errors exist.
if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
// Build message.
function build_message($request_input){if(!isset($message_o utput)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$ message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$mess age_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
$message = build_message($_REQUEST);
$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."";
$message = stripslashes($message);
$subject = "FormToEmail Comments";
$headers = "From: " . $_REQUEST['email'];

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<title>Dreamweaver Tutorial - Contact Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body bgcolor="#ffffff" text="#000000">
<p><b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>
<br>Your message has been sent</p>
<p><a href="thanks.htm">Click Here</a></p>
Many thanks