我正在为我的公司提交报价提交表单,并遇到表单功能的问题(即,“提交”按钮不执行任何操作)。目前,表格如下:
<form action="quotethanks.php" form id="contact-form">
<fieldset>
<p>
<label class="name">
<input type="text" name="first" value="First Name:*">
<span class="errors"><span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span></span></label>
<label class="name">
<input type="text" name="last" value="Last Name:*">
<span class="errors"><span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span></span></label>
<label class="name">
<input type="text" name="business" value="Business Name:*">
<span class="errors"><span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span></span></label>
<label class="email">
<input type="text" name="email" value="E-mail Address:*">
<span class="errors"><span class="error">*This is not a valid email.</span> <span class="empty">*This field is required.</span></span></label>
<label class="phone">
<input type="text" name="phone" value="Phone Number:*">
<span class="errors"><span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span></span></label>
<label class="message"> Type of quote: *
<select name="type">
<option value="Display Case">Display Case</option>
<option value="Case Part"> Case Part</option>
<option value="Service"> Service</option>
<option value="Other"> Other</option>
</select></label>
<br><br>If "other," please define:
<textarea name="define" id="define"></textarea>
<br><Br>
<label class="name">
<input type="text" name="model" value="Equipment Model Number (if known)">
</label>
<label class="name">
<input type="text" name="serial" value="Equipment Serial Number (if known)">
</label>
Quote Description:
<textarea name="description" id="description"></textarea>
<br><br>
<label class="name">
<input type="text" name="offer" value="Offer Code (if applicable)">
</label>
<div class="clear"></div>
<div class="btns">
<a class="button" data-type="submit">Submit</a>
<a class="button" data-type="reset">Clear</a>
<div class="clear"></div>
</p>
</p>
</fieldset>
</form>
然后应该将输入的数据发送到quote_mailer.php,然后重定向到quotethanks.php(最后一行代码):
<?php
/*Subject and email variables */
$emailSubject = 'Quote Request Submitted';
$webMaster = 'lmiller@rsiclimate.com';
/* Gathering Data Variables */
$firstField = $_POST['first'];
$lastField = $_POST['last'];
$businessField = $_POST['business'];
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$typeField = $_POST['type'];
$defineField = $_POST['define'];
$modelField = $_POST['model'];
$serialField = $_POST['serial'];
$descriptionField = $_POST['description'];
$offerField = $_POST['offer'];
$body = "<br><hr><br>";
$body.= "Name: ".$firstField." ".$lastField." <br>";
$body.= "Business Name: ".$businessField." <br>";
$body.= "Email: ".$emailField." <br>";
$body.= "Phone Number: ".$phoneField." <br>";
$body.= "Quote Type: ".$typeField." <br>";
$body.= "If other, define: ".$defineField." <br>";
$body.= "Model Number, if known: ".$modelField." <br>";
$body.= "Serial Number, if known: ".$serialField." <br>";
$body.= "Quote Description: ".$descriptionField." <br>";
$body.= "Offer Code: ".$offerField." <br>";
$headers = "From: ".$emailField."\r\n";
$headers .= "Content-type: text/html\r\n";
if(mail($webMaster, $emailSubject, $body, $headers))
header('Location: contact-form-thank-you.html');
?>
我遇到的问题是在表单的实际页面上,输入所有数据,然后“提交”按钮不执行任何操作。它出现了,您可以单击它,但出于所有可见的目的,没有任何反应。虽然我已经使用HTML了一点点,但创建PHP驱动的表单对我来说相对较新,所以我并没有真正看到这个代码中可能存在的问题。
任何方向都会非常感谢!
答案 0 :(得分:1)
您需要使用输入提交而不是锚点,因此请更改此
<a class="button" data-type="submit">Submit</a>
要
<input class="button" type="submit" name="submit">Submit</a>
在您的PHP代码中添加检查按钮的isset()
if(isset($_POST['submit']))
{
$emailSubject = 'Quote Request Submitted';
$webMaster = 'lmiller@rsiclimate.com';
//all your code here
} else {
//print the form
}