2014-02-09 50 views
0

我有一個隱藏的div,我正在加載點擊提交按鈕。表單也發送頁面加載結果?我確定我包含了validateForm()函數,並且在提交函數結束時用return validateForm()函數調用它。當我點擊提交時,它也正在加載隱藏的div併發送結果。我究竟做錯了什麼?表單發送頁面加載結果

<?php 
$name = $_POST['name']; 
$address = $_POST['address']; 
$city = $_POST['city']; 
$state = $_POST['state']; 
$phone = $_POST['phone']; 
$email = $_POST['email']; 

$name = stripslashes($name); 
$address = stripslashes($address); 
$city = stripslashes($city); 
$state = stripslashes($state); 
$phone = stripslashes($phone); 
$email = stripslashes($email); 


$to = '[email protected] ' . ', '; 
$to .= $Email; 

$from = "$Email "; 
$subject = 'Look and Learn: Applicant'; 
$message = <<<EOF 
<html> 
<body bgcolor="#FFFFFF"> 

<b>Look and Learn: Applicant</b><br /><br /> 

<b>Name:</b> $name<br /> 
<b>Address:</b> $address/$city, $state<br /> 
<b>Phone:</b> $phone<br /> 
<b>Email:</b> $email<br /> 

</body> 
</html> 
EOF; 
//end of message 

// Additional headers 
$headers .= 'From: Razor Chic of Atlanta <[email protected]>' . "\r\n"; 
$headers .= "Content-type: text/html\r\n"; 
$to = "$to"; 

mail($to, $subject, $message, $headers); 

?> 


<!doctype html> 
<html lang="en"> 
<head> 
<meta charset="UTF-8" /> 
<title>Sign Up</title> 
<link rel="stylesheet" href="css/sign-up.css"> 
<script type="text/javascript" src="js/jquery.js"></script> 
<script type="text/javascript" src="js/script.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script> 

<script type="text/javascript"> 


$(document).ready(function() { 
$('#submit').click(function() { 
$('#thankyou').show(); 
$("#hidden1").html($("#thankyou").html()); 
}); 
}); 

</script> 

<script> 

function validateForm() 
{ 

var x=document.forms["myContact"]["name"].value; 
if (x==null || x=="") 
{ 
alert("Please Enter Your Full Name"); 
return false; 
} 

var x=document.forms["myContact"]["address"].value; 
if (x==null || x=="") 
{ 
alert("Please Enter Your Address"); 
return false; 
} 

var x=document.forms["myContact"]["city"].value; 
if (x==null || x=="") 
{ 
alert("Please Enter Your City"); 
return false; 
} 

var x=document.forms["myContact"]["phone"].value; 
if (x==null || x=="") 
{ 
alert("Please Enter Your Phone Number"); 
return false; 
} 

var x=document.forms["myContact"]["email"].value; 
if (x==null || x=="") 
{ 
alert("Please Enter Your Email"); 
return false; 
} 

} 


$('#myContact').submit(function() { 

$.each($('#myContact .notShouldBeBlank'), function() 
{ 
if($(this).val() == ''){ 
$(this).after('<span class="error">This field is required.</span>'); 
return false; 
} 
}); 

return validateForm(); 
} 
</script> 


</head> 
<body style="overflow: hidden; overflow-x: hidden; overflow-y: hidden;"> 



<div id="wrap"> 
<div id="hidden1"></div> 
<div style="font-size: 18px; font-weight: bold; font-family: Verdana, Geneva, sans-serif;"> 
Sign-Up: Look And Learn Class 
</div> 

<br> 

<form id="myContact" action="" name="myContact" method="post" enctype="multipart/form-data"> 
<div> 
<label> 
<span>Name: *</span><br> 
<input name="name" type="text" size="64" placeholder="Name"> 
</label> 
</div> 

<div> 
<table width="100%" > 

<tr> 

<td width="230"> 
<label> 
<span>Address: *</span><br> 
<input placeholder="Address" size="100" type="text" name="address" maxlength="100"> 
</label> 
</td> 

<td width="160"> 
<label> 
<span>City *</span><br> 
<input placeholder="City" name="city" type="text" id="city" maxlength="100" /> 
</label> 
</td> 

<td width="189"> 
<label> 
<span>State *</span><br> 
<input placeholder="State" name="city" type="text" id="city" maxlength="3" /> 
</label> 
</td> 
</tr> 

</table> 
</div> 

<div> 
<label> 
<span>Phone: *</span><br> 
<input placeholder="Phone" size="64" type="text" name="phone"> 
</label> 
</div> 


<div> 
<label> 
<span>Email: *</span><br> 
<input placeholder="Email address" size="64" type="email" name="email"> 
</label> 
</div> 

<div> 
<button name="submit" type="submit" id="submit">S I G N U P</button> 
</div> 
</form> 
<p>Note: * Fields are required</p> 

</div> 


<!---- THANK YOU----> 
<?php 
if($sent){ 

echo '<div id="thankyou" style="display:block;">'; 
} 
else{ 
echo '<div id="thankyou" style="display:none;">'; 
} 
?> 


<!---- PAY BEGINS ----> 
<div id="paynow1-wrapper"> 
<div id="paynow1"> 

<form method="post" action="https://www.paypal.com/cgi-bin/webscr"> 
<input type="hidden" name="cmd" value="_cart"> 
<input type="hidden" name="add" value="1"> 
<input type="hidden" name="business" value="[email protected]"> 
<input type="hidden" name="item_name" value="Look and Learn: Deposit"> 
<input type="hidden" name="amount" value="100.00">    
<input type="hidden" name="return" value="http://thebrlab.com/razor-chic-of-atlanta/thank-you.html"> 
<input type="hidden" name="undefined_quantity" value="1"> 

<input style="background: none" onMouseOver="this.src='images/pay-now-up.png'" onMouseOut="this.src='images/pay-now-down.png'" type="image" src="images/pay-now-down.png" height="41" width="141" border="0" alt="Pay Now" class="button"> 

</form> 

</div> 
</div> 
<!---- PAY ENDS ----> 


<!---- PAY BEGINS ----> 
<div id="paynow2-wrapper"> 
<div id="paynow2"> 

<form method="post" action="https://www.paypal.com/cgi-bin/webscr"> 
<input type="hidden" name="cmd" value="_cart"> 
<input type="hidden" name="add" value="1"> 
<input type="hidden" name="business" value="[email protected]"> 
<input type="hidden" name="item_name" value="Look and Learn: Balance"> 
<input type="hidden" name="amount" value="99.00">    
<input type="hidden" name="return" value="http://thebrlab.com/razor-chic-of-atlanta/thank-you.html"> 
<input type="hidden" name="undefined_quantity" value="1"> 

<input style="background: none" onMouseOver="this.src='images/pay-now-up.png'" onMouseOut="this.src='images/pay-now-down.png'" type="image" src="images/pay-now-down.png" height="41" width="141" border="0" alt="Pay Now" class="button"> 

</form> 

</div> 
</div> 
<!---- PAY ENDS ----> 



<!---- PAY BEGINS ----> 
<div id="paynow3-wrapper"> 
<div id="paynow3"> 

<form method="post" action="https://www.paypal.com/cgi-bin/webscr"> 
<input type="hidden" name="cmd" value="_cart"> 
<input type="hidden" name="add" value="1"> 
<input type="hidden" name="business" value="[email protected]"> 
<input type="hidden" name="item_name" value="Look and Learn: Full Payment"> 
<input type="hidden" name="amount" value="199.00">    
<input type="hidden" name="return" value="http://thebrlab.com/razor-chic-of-atlanta/thank-you.html"> 
<input type="hidden" name="undefined_quantity" value="1"> 

<input style="background: none" onMouseOver="this.src='images/pay-now-up.png'" onMouseOut="this.src='images/pay-now-down.png'" type="image" src="images/pay-now-down.png" height="41" width="141" border="0" alt="Pay Now" class="button"> 

</form> 

</div> 
</div> 
<!---- PAY ENDS ----> 



<img src="images/thank-you/look-and-learn1.png" /> 

</div> 
<!---- THANK YOU----> 


</body> 
</html> 
+0

有人pleaseeeee幫助我,並指出這裏有什麼不對? –

+0

對不起,我忘了在最初的帖子中包含我的最新評論。我是堆棧溢出Dagon的新手......謝謝。你能幫我嗎? –

回答

2

你問「的形式也發送頁面加載的結果嗎?」,那麼,如果你的意思是在頁面加載郵件()被執行,那麼你會是正確的。通常的模式是測試是否設置了一些請求變量,然後才調用mail(),例如,

if (isset($_POST['name'])) { 
    mail($to, $subject, $message, $headers); 
} 
相關問題