dongqishun6409 2017-01-23 11:48
浏览 47

不接收来自PHP联系表单的所有字段的输入

This has been bugging me all day and I've given up trying to figure it out for myself, but the answer's probably really obvious...

My contact form works fine, however I don't receive input for all fields. I only get name, phone, email and message. I've given the form fields a name attribute so I'm not sure what's happening.

Here is the HTML:

<form name="sentMessage" id="contactForm" novalidate>
                        <div class="row">
                            <div class="col-md-6">
                              
                               <div class="form-group">
                                    <input type="name" class="form-control" placeholder="Your Name *" name="name" id="name" required data-validation-required-message="Please enter your name.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                
                                <div class="form-group">
                                    <input type="phone" class="form-control" placeholder="Your Phone Number *" name="phone" id="phone" required data-validation-required-message="Please enter your phone number.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                
                                <div class="form-group">
                                    <input type="email" class="form-control" placeholder="Your Email *" name="email" id="email" required data-validation-required-message="Please enter your email address.">
                                    <p class="help-block text-danger"></p>
                                </div>
                                
                                   <div class="form-group">
                                    <input type="text" class="form-control" name="suburb" placeholder="Your Suburb *" id="suburb" required data-validation-required-message="Please enter your address.">
                                    <p class="help-block text-danger"></p>
                                </div> 
                                
                              <div class="select"> 
                               <div class="col-sm-6">
                                <div class="form-group">
                    <select class="selectpicker" name="state" id="state" data-width="100%" data-height="100%" title="Choose State *" data-style="btn-primary">                 
                        <option>QLD</option>
                        <option>NSW</option>
                </select>
                </div>    
                   </div>
                  </div>
                               
                               <div class="right-form-column">
                                <div class="col-sm-6">
                                 <div class="form-group">
                                    <input type="number" class="form-control" placeholder="Post Code *" name="postcode" id="postcode" required data-validation-required-message="Please enter your post code.">
                                    <p class="help-block text-danger"></p>
                                 </div>                                              
                                </div>
                   </div>                                                                                           
                  </div>
                            
                              <div class="col-md-6">
                  <div class="select"> 
                               <div class="col-xs-6">
                                <div class="form-group">
                    <select class="selectpicker" name="product1" id="product1" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
                                         <optgroup label="100 Series">                     
                                             <option>90mm Grey Standard</option>
                                             </optgroup> 
                                         </select>
                                    </div>    
                                </div>
                              </div>
                               
                               <div class="right-form-column">
                                <div class="col-xs-6">
                                 <div class="form-group">
                                    <input type="number" class="form-control" placeholder="Quantity" name="quantity1" id="quantity1">
                                    <p class="help-block text-danger"></p>
                                 </div>                                              
                                </div>
                </div>        
                              
                            <div class="select">
                             <div class="col-xs-6">
                                <div class="form-group">
                    <select class="selectpicker" name="product2" id="product2" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
                                         <optgroup label="100 Series">                     
                                             <option>90mm Grey Standard</option>
                                             </optgroup> 
                                         </select>
                                </div>    
                               </div>
                                            </div>
                               
                                 <div class="right-form-column">
                                <div class="col-xs-6">
                                 <div class="form-group">
                                    <input type="number" class="form-control" placeholder="Quantity" name="quantity2" id="quantity2">
                                    <p class="help-block text-danger"></p>
                                 </div>                                              
                                </div>
                </div>     
                              
                             <div class="select">
                             <div class="col-xs-6">
                                <div class="form-group">
                        <select class="selectpicker" name="product3" id="product3" data-width="100%" data-height="100%" data-live-search="true" title="Choose Product" data-style="btn-primary">
                                         <optgroup label="100 Series">                     
                                             <option>90mm Grey Standard</option>
                                             </optgroup> 
                                         </select>
                                </div>    
                               </div>
                                            </div>
                               
                                 <div class="right-form-column">
                                <div class="col-xs-6">
                                 <div class="form-group">
                                    <input type="number" class="form-control" placeholder="Quantity" name="quantity3" id="quantity3">
                                    <p class="help-block text-danger"></p>
                                 </div>                                              
                                </div>
                </div>     
                                          
                                <div class="form-group">
                                    <textarea class="form-control" placeholder="Additional comments" name="message" id="message"></textarea>
                                    <p class="help-block text-danger"></p>
                                </div>
                            </div>
                            
                            <div class="clearfix"></div>
                            <div class="col-lg-12 text-center">
                                <div id="success"></div>
                                <button type="submit" class="btn btn-xl" name="submit">submit</button>
                            </div>
                        </div>
                    </form>

And the PHP:

<?php
// check if fields passed are empty
if(empty($_POST['name'])        ||
   empty($_POST['phone'])       ||
   empty($_POST['email'])       ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
    echo "No arguments Provided!";
    return false;
}

$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];

// create email body and send it    
$to = 'myname@mydomain.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "P Services Contact Form:  $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.

"."Here are the details: From: $name
 Phone: $phone
 E-Mail: $email_address
 Suburb: $suburb
 State: $state
 Post Code: $postcode
 Product: $product1
 Quantity: $quantity1
 Product: $product2
 Quantity: $quantity2
 Product: $product3
 Quantity: $quantity3
 Message:
 $message";
$headers = "From: noreply@yourdomain.com
";
$headers .= "Reply-To: $email_address"; 
if(mail($to,$email_subject,$email_body,$headers)){ 
    echo "Mail sent successfully.";
} 
    else{ echo "Error.";
}        
?>
</div>
  • 写回答

2条回答 默认 最新

  • dtvhqlc57127 2017-01-23 12:03
    关注

    The only thing you need to change is specify the method of form submission (POST or GET).

    Either use

    <form name="sentMessage" id="contactForm" novalidate method="POST">

    OR

    Access the form variables using $_GET like $_GET['name'])

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP