duanran3115 2015-04-20 13:20
浏览 55
已采纳

isset($ _POST ['submit'])总是返回false(我没有忘记name =“submit”)[关闭]

I've the following HTML form:

<form class="page-footer_enquiry-form" id="page-footer_enquiry-form" method="post" autocomplete="on" action="../php/enquiry.php">
    <h2 class="page-footer_enquiry-form-title">Enquiry</h2>
    <!-- Name -->
    <div class="page-footer_enquiry-form-name">
        <label for="footer-enquiry-name">
            <span class="page-footer_enquiry-form-label">Full Name</span>
            <input type="text" id="footer-enquiry-name" name="fullname">
        </label>
    </div>
    <!-- Email -->
    <div class="page-footer_enquiry-form-email">
        <label for="footer-enquiry-email">
            <span class="page-footer_enquiry-form-label">Email Address</span>
            <input type="email" id="footer-enquiry-email" name="email">
        </label>
    </div>
    <!-- Message -->
    <div class="page-footer_enquiry-form-message">
        <label for="footer-enquiry-message">
            <span class="page-footer_enquiry-form-label">Message</span>
            <textarea name="message" id="footer-enquiry-message" rows="10" cols="50"></textarea>
        </label>
    </div>
    <input name="submit" type="submit" value="Send Message" class="button-dark">
    <p class="page-footer_enquiry-form-dialog"></p>
</form>

Which is "handled" by the following PHP:

if( isset( $_POST['submit'] ) ){
    echo 'first';
} else {
    echo 'second';
};

Whenever I press the submit button, I'm getting 'second' (logged to the console via js).

EDIT - The jQuery:

handler : function(){
    var jqxhr = $.ajax({
        type: 'POST',
        url: '../php/enquiry.php',
        data: $('#page-footer_enquiry-form').serialize() + "&js=true",
        success : function(res) {
            console.log(res);
        }
    });
},

I fear it'll be something obvious to somebody else, but I just can't identify the problem. Help, please.

  • 写回答

1条回答 默认 最新

  • dongroufan6846 2015-04-20 13:38
    关注

    If you have a look at documentation of serialize() https://api.jquery.com/serialize/ you will find the following:

    No submit button value is serialized since the form was not submitted using a button.

    I think that causes your problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)