duanran3115 2015-04-20 05: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 05: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部