为什么序列化不包含提交按钮名称? [英] Why serialize does not include submit button name?

查看:82
本文介绍了为什么序列化不包含提交按钮名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么序列化(jQuery)不包含提交按钮名称?

Why serialize (Jquery) does not include submit button name?

在PHP中,我通常这样做:

In PHP I normally do this:

if (isset($_POST['submit_signup'])) {
    print_r($_POST);
    //Then check firstname, password, etc POSTS
}

那不起作用,对此有什么解决方案?

That don't work, what is the solution to this?

推荐答案

不确定这是否是最优雅的解决方案,但是您可以使用隐藏的输入框来包含一个值(最好是变化的东西,例如某种哈希) )并检查.喜欢:

Not sure if this is the most elegant solution, but you can use a hidden input box to contain a value (preferably something that changes, like a sort of hash) and check for that. Like:

<input type="hidden" name="signup_submitted" value="random_hash" />

在您的代码中,您可以执行以下操作:

And in your code you can do:

if(isset($_POST['signup_submitted']))
{
    // Do your work;
}

警告:哈希在这里并不是安全的事情,而只是一种用来做与您习惯相同的事情的方法.

Warning: A hash is not a security thing here, only a way to do the same thing you're used to.

小更新:我注意到您还问过为什么",jQuery在serialize()输出中不包含提交"按钮.这是HTML草案中指定的默认行为.只要没有按下提交按钮,就不应将其包含在已提交(或序列化)的数据中. jQuery的创建者决定尊重这一点,并且不将其包含在序列化的字符串中.

Small Update: I noticed you also asked 'why' JQuery does not include the submit button in the serialize() output. This is default behaviour as specified in the HTML draft(s). As long as no submit button is pressed, it should not be included in the submitted (or serialized) data. The JQuery creators decided to honour that and not include it in the serialized string.

这篇关于为什么序列化不包含提交按钮名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆