每次我单击提交按钮时,页面都会重定向。
我如何设置它以使页面不会重定向并且它运行服务器端代码并停留在当前页面上并在我的表单上方回显?
HTML 代码:
<form name="contact_form" method="post" action="mail.php">
<table border="0">
<tbody class="Form">
<tr>
<td>
<label for="NameInput">Your Name:<font color="#FF0000">*</font></label>
<input autofocus="autofocus" placeholder="John Doe" id="NameInput" name="NameInput" required="required" />
</td>
</tr>
<tr>
<td>
<label for="CompanyName">Your Company:<font color="#FF0000">*</font></label>
<input required="required" placeholder="Warner bros." id="CompanyName" name="CompanyName" />
</td>
</tr>
<tr>
<td>
<label id="PhoneNumber" name="PhoneNumber">Phone: </label>
<input placeholder="888-888-8888" id="PhoneNumber" name="PhoneNumber"/>
</td>
</tr>
<tr>
<td>
<label id="Email" name="Email">Email:<font color="#FF0000">*</font></label>
<input required="required" placeholder="johndoe@gmail.com" id="Email" name="Email" type="email" />
</td>
</tr>
<tr>
<td>
<label for="Website">Website: </label>
<input placeholder="https://" id="Website" name="Website" />
</td>
</tr>
</tbody>
</table>
<br/>
<br/>
<br/>
<br/>
<p><strong>What interests you, broadly speaking?</strong></p>
<br/>
<p><input id="WebDesignCheckbox" name="WebDesignCheckbox" type="checkbox">Web Design/Development</input></p>
<input id="SocialMediaCheckbox" name="SocialMediaCheckbox" type="checkbox">Social Media</input>
>
<input id="MobilePresence" name="MobilePresence" type="checkbox">Mobile Presence</input>
<input id="OnlineAdvertising" name="OnlineAdvertising" type="checkbox">Online Advertising</input>
<input id="SEOCheckbox" name="SEOCheckbox" type="checkbox">Search Engine Optamization</input>
<p><input id="ecommerceCheckbox" name="ecommerceCheckbox" type="checkbox" >eCommerce</input></p>
<br/>
<label for="comments">Your Ideas to Life?</label><br/>
<textarea placeholder="How can we help you?" id="comments" name="comments" style="margin: 2px; height: 137px; width: 437px;"></textarea></td></tr><br/>
<tr>
<td><input type="submit" id="Submit" name="Submit" value="Submit" align="middle" /></td>
</tr>
<p id="req-field-desc"><span class="required">*</span> indicates a required field</p>
</form>
PHP 脚本 mail.php:
<?php
if( isset($_POST) ){
//form validation vars
$formok = true;
$errors = array();
//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');
//form data
$NameInput = $_POST['NameInput'];
$CompanyName = $_POST['CompanyName'];
$PhoneNumber = $_POST['PhoneNumber'];
$Email = $_POST['Email'];
$Website = $_POST['Website'];
$WebDesignCheckbox = $_POST['WebDesignCheckbox'];
$SocialMediaCheckbox = $_POST['SocialMediaCheckbox'];
$MobilePresence = $_POST['MobilePresence'];
$OnlineAdvertising = $_POST['OnlineAdvertising'];
$SEOCheckbox = $_POST['SEOCheckbox'];
$ecommerceCheckbox = $_POST['ecommerceCheckbox'];
$comments = $_POST['comments'];
//form validation
if(empty($NameInput)){
$formok - false;
$errors[] = "You have not entered a name.";
}
if(empty($CompanyName)){
$formok = false;
$errors[] = "You have not entered a company name.";
}
if(empty($Email)){
$formok = false;
$errors[] = "You have not entered an email address.";
}
//send email if checks out
if($formok){
ini_set("sendmail_from","keeano@doodleinc.co");
/*$headers="From: Contact Page: {$Email}" . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";*/
$emailbody = "
<p>Time: {$time} \n {$date}</p>
<p>You are recieving this from your websites contact form.</p>
<p><strong>Contacts Name: </strong> {$NameInput}</p>
<p><strong>Companys Name: </strong> {$CompanyName}</p>
<p><strong>Phone Number: </strong> {$PhoneNumber}</p>
<p><strong>Email: </strong> {$Email}</p>
<p><strong>Website: </strong> {$Website}</p>
<p><strong>Web Design Checkbox: </strong> {$WebDesignCheckbox}</p>
<p><strong>Social Media Checkbox: </strong> {$SocialMediaCheckbox}</p>
<p><strong>Mobile Presence: </strong> {$MobilePresence}</p>
<p><strong>Online Advertising: </strong> {$OnlineAdvertising}</p>
<p><strong>SEO Checkbox: </strong> {$SEOCheckbox}</p>
<p><strong>eCommerce Checkbox: </strong> {$ecommerceCheckbox}</p>
<p><strong>Comments: </strong> {$comments}</p>
<p><strong>Extra Data Obtained:</strong>\n Users IPAddress: {$ipaddress}</p>
";
mail("keeano@doodleinc.co", "Contacts Page Enquiry", $emailbody);
echo('<p style="font-weight: bold; color: #709900"><em>Thank you for contacting doodle Inc., someone will contact you within 48 hours.</em></p>');
}
}
我只是想让它在表单顶部创建一个标签,上面写着“谢谢,有人会在 48 小时内与您联系”。
如果有人可以帮助我,那将是很好的以及详细的解释,所以我再也不会遇到这个问题了。