Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jdl8422

macrumors 6502
Original poster
Jul 5, 2006
491
0
Louisiana
Well i figured out how to do the multipage form. It works all the way up to the submit part. I modified a contact form for the php. I want the email that is send to break down each question. I don't think there are any syntax errors but i don't know. If anyone can help that would be great. Thanks in advance

HTML:
<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[i].id.indexOf("C")!=-1||form[i].id.indexOf("B")!=-1)//Skip Continue and Back Buttons
			continue;
		values += form[i].id;
		values += ': ';
		values += form[i].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="send.php" onSubmit="send.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" onClick="send.php"></p>
</div>
</form>


</body>

</html>



PHP:
<?php
if(isset($_POST['submit'])) {
$to = "jdl8422@yahoo.com";
$subject = "Form";
$t1 = $_POST['question1'];
$t2 = $_POST['question2'];
$t3 = $_POST['question3'];
$t4 = $_POST['question4'];
$t5 = $_POST['question5'];
$t6 = $_POST['question6'];
$t7 = $_POST['question7'];
$t8 = $_POST['question8'];
$t9 = $_POST['question9'];
$t10 = $_POST['question10'];
$t11 = $_POST['question11'];
$t12 = $_POST['question12'];
$t13 = $_POST['question13'];
$t14 = $_POST['question14'];
$t15 = $_POST['question15'];
$t16 = $_POST['question16'];
$t17 = $_POST['question17'];
$t18 = $_POST['question18'];
$t19 = $_POST['question19'];
$t20 = $_POST['question20'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:$t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12, $t13, $t14, $t15, $t16, $t17, $t18, $t19, $t20\n ";
 
echo "Data has been submitted to $to!";
mail($to, $subject, $body, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12, $t13, $t14, $t15, $t16, $t17, $t18, $t19, $t20);
} else {
echo "Sorry!";
}
?>
 
Delete "onSubmit="send.php"" from the form tag in the HTML. That is only for JavaScript, not PHP. It could be causing errors.

Also, can you explain the incorrect behavior that is occurring? You've only said it didn't work. In what way is it not working?
 
sorry, I guess i cant assume everyone knows what Im talking about. When I hit submit, it is suppose to use the send.php script. If the email is sent it says so. If it does not send it says sorry. Right now it is saying sorry, so im guessing it has an error of some kind

Here is the link to the form.
 
In your PHP you check if a 'submit' item was sent, but your form doesn't contain an element named submit. You need to have a variable by that name. You might be able to use the following for the Submit button so that it's a variable as well.

HTML:
<input name="submit" type="submit" value="Submit" onClick="send.php">

The only thing added is the name attribute. I'm not 100% that'll work, but try it first. If it doesn't, add a hidden form field with the attribute name 'submit' and that'll get it into your if statement.

HTML:
<input name="submit" type="hidden" value="submitted">
 
Ok, Can someone please tell me why I get this error

Parse error: parse error, unexpected ',' in /home/content/j/d/l/jdl8422/html/survey/send.php on line 2


I tried both ' and "

PHP:
<?php
$to = "jdl8422@yahoo.com";
$subject = "Form";
$t1 = $_POST['question1'];
$t2 = $_POST['question2'];
$t3 = $_POST['question3'];
$t4 = $_POST['question4'];
$t5 = $_POST['question5'];
$t6 = $_POST['question6'];
$t7 = $_POST['question7'];
$t8 = $_POST['question8'];
$t9 = $_POST['question9'];
$t10 = $_POST['question10'];
$t11 = $_POST['question11'];
$t12 = $_POST['question12'];
$t13 = $_POST['question13'];
$t14 = $_POST['question14'];
$t15 = $_POST['question15'];
$t16 = $_POST['question16'];
$t17 = $_POST['question17'];
$t18 = $_POST['question18'];
$t19 = $_POST['question19'];
$t20 = $_POST['question20'];
$questions = ($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12, $t13, $t14, $t15, $t16, $t17, $t18, $t19, $t20);

$message = "From: $name_field\n E-Mail: $email_field\n Message: $questions\n ";
 
mail ($to, $subject, $message);

?>
 
Sometimes it gets confused on line numbers. The error is with your $questions variable. You aren't defining it as an array.

PHP:
$questions = array($t1, ... );
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.