dougui1977 2014-03-20 22:10
浏览 64
已采纳

HTML / PHP电子邮件表单:提交按钮不响应

I'm working on a quote submission form for my company, and running into an issue with the form functionality (namely, the Submit button does nothing). Currently, the form is below:

<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>

This should then send the entered data to quote_mailer.php, and then redirect to quotethanks.php (the last line of code):

<?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."
"; 
$headers .= "Content-type: text/html
"; 
if(mail($webMaster, $emailSubject, $body, $headers)) 
header('Location: contact-form-thank-you.html'); 
?>

The issue I'm running into is on the form's actual page, all data gets entered, and then the Submit button does nothing. It shows up, you can click it, but for all visible purposes nothing happens. While I've worked with HTML more than a little, creating PHP-driven forms is relatively new to me so I'm not really seeing where in this code an issue might be.

Any direction would be greatly appreciated!

  • 写回答

1条回答 默认 最新

  • doumindang2416 2014-03-20 22:15
    关注

    You need to use an input submit and not an anchor, so change this

    <a class="button" data-type="submit">Submit</a>
    

    To

    <input class="button" type="submit" name="submit">Submit</a>
    

    In your php code add instead a checking for isset() of the button

    if(isset($_POST['submit']))
    {
        $emailSubject = 'Quote Request Submitted'; 
        $webMaster = 'lmiller@rsiclimate.com'; 
       //all your code here
    } else {
       //print the form
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致