php mail form text wont appear / javascript included
Posted on
16th Feb 2014 07:03 pm by
admin
Guys/gals...
I am running into a problem whereby I have a great piece of javascript code that mimicks multi-page forms (see www.mtsgroup.co.uk/multiPageForm.htm).....
The problem is the php file wont handle saving and sending the filled in forms by email (the emails are blank).....
The php works fine on single page forms and the multiform javascript works fine when I put a print screen action rather than a send via email.... so there must be something in the php that isn't liking retrieving the saved text and sending it via email.....
The html script is as follows
<html>
<head>
<title>Multi-Page Form</title>
<script language="JavaScript">
var currentLayer = 'page1';
function showLayer(lyr){
hideLayer(currentLayer);
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.id.indexOf("C")!=-1||form.id.indexOf("B")!=-1)//Skip Continue and Back Buttons
continue;
values += form.id;
values += ': ';
values += form.value;
values += 'n';
}
alert(values);
}
</script>
<style>
body{
font: 10pt sans-serif;
}
.page{
position: absolute;
top: 10;
left: 100;
visibility: hidden;
}
</style>
</head>
<body>
<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>
<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>
<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>
<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>
</div>
</form>
</body>
</html>
and the php script is as follows
<?php
error_reporting(E_ALL ^ E_NOTICE);
$my_email = "stephen.reece@mtsgroup.co.uk";
$from_email = "";
$continue = "/";
$errors = array();
// Remove $_COOKIE elements from $_REQUEST.
if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
// Validate email field.
if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{
$_REQUEST['email'] = trim($_REQUEST['email']);
if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}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.
function recursive_array_check_blank($element_value)
{
global $set;
if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{
foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
}
}
recursive_array_check_blank($_REQUEST);
if(!$set){$errors[] = "You cannot send a blank form";}
unset($set);
// Display any errors and exit if errors exist.
if(count($errors)){foreach($errors as $value){print "$value
";} exit;}
if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "rn" : "n");}
// Build message.
function build_message($request_input){if(!isset($message_output)){$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{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
$message = build_message($_REQUEST);
$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com";
$message = stripslashes($message);
$subject = "FormToEmail Comments";
$subject = stripslashes($subject);
if($from_email)
{
$headers = "From: " . $from_email;
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST['email'];
}
else
{
$from_name = "";
if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}
$headers = "From: {$from_name} <{$_REQUEST['email']}>";
}
mail($my_email,$subject,$message,$headers);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form To Email PHP script from FormToEmail.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
<div>
<center>
<b>Thank you <?php if(isset($_REQUEST['name'])){print stripslashes($_REQUEST['name']);} ?></b>
Your message has been sent
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>
<p><b>FormToEmail</b> by <a href="http://FormToEmail.com">FormToEmail.com</a></p>
</center>
</div>
</body>
</html>
No comments posted yet
Your Answer:
Login to answer
269
22
Other forums
PHP error (line 38) my website
Hello everyone, I'm new on this
and I got a web site thats got a error not showing the photos on<
foreach iterator
Hi Guys
Does the foreach loop have an inbuilt iterator ?
how to populate a drop down box
Hi buddies!
PROCEDURE DOWNLOAD_REPORT_FORM (report_name varchar)
is
begin
DOWNLO
GIS appliction help
I found some tutorials in the internet to develop a map application I don't want to use google maps
Windows 7
Windows 7 default user account control worries experts. Corporate IT departments should be pleased w
[Need Help] php timing issues
I don't know what is going wrong. I need some help with being able to set an image at 9:00am Colorad
rookie looking for help coding a CSS form with PHP
I'm trying to figure out how to add PHP code to my xhtml form so that it is a working form embedded
How to pass parameter to tag query?
Hi,
I want to get the value of a tag at a specific time (like 10/27/09 15:29:59), I need to giv
check comment for html
hi, I just wanted to check if a comment a user posts contains HTML, and if it does, to not allow it
Frustrated php Newbie
First off, I am pretty much a PHP nub. I can read and understand the language (most of the time) so