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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了