PHP $ _POST变量数组的数组存储 [英] Storing array of PHP $_POST variables as array

查看:264
本文介绍了PHP $ _POST变量数组的数组存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作就一个字preSS的过程,但是这似乎更像是特别相关的字preSS一般PHP和数组操作的问题,在有关WooCommerce这种情况。

I'm working on a WordPress process, but this seems more like a general PHP and array manipulation question with specific relevance to WordPress, in this case relating to WooCommerce.

如果我有可能从任何地方1提交相同类型的约35项,那么我的理解一个形式,我可以按如下方式创建它。我使用的姓氏和名字。

If I have a form that may submit anywhere from 1 to around 35 entries of the same type, then to my understanding I can create it as follows. I'm using first and last names.

该表单输入,简化的,是这样的:

The form inputs, simplified, look like this:

echo '  <input type="text" name="first_name[]" id="first_name" />';
echo '  <input type="text" name="last_name[]" id="last_name" />';

在上述的完整版本,线被复制为根据需要许多时间,用迭代变量区分的ID顺序地从彼此的,并与其它值$ P $对填充和隐藏。还有是要发布变量作为隐藏字段并行版本。

In the full version of the above, lines are replicated as many time as necessary, with an iterated variable distinguishing ids sequentially from each other, and with other values pre-filled and hidden. There's a parallel version meant to post variables as hidden fields.

该职位的行动看起来是这样的:

The post action looks like this:

if (isset($_POST) == true) {
    $att_data = array(
        'last_name'         => $_POST['last_name'],
        'first_name'        => $_POST['first_name']
    );

在Word preSS功能add_post_meta那么应该$ att_data添加到数据库中。它工作正常,作为一个直接到位的$ _ POST没有形式增加的动作,或用虚拟变量[...]。然而不幸的是,用什么样的形式版本/提交/ $ _ POST给我我调试控制台上

The WordPress function add_post_meta then ought to add $att_data to the database. It works fine as a direct "add" action without a form, or with a dummy variable in place of the $_POST[...]. Unfortunately, however, what using versions of the form/submit/$_POST gives me on my debug console is

["last_name"]=> NULL ["first_name"]=> NULL 

那么,表格被提交或至少后动作张贴和正在发送的阵列,但$ _POST变量不被捕获。为什么不呢?

So, the form is submitting or at least the post action is posting and the the array is being sent, but the $_POST variables are not being captured. Why not?

补充:等一下 - 我想知道如果WooCommerce重新定向...我现在研究前清除所有$ _ POST变量。

ADDITIONAL: Wait a second - I'm wondering if WooCommerce clears all $_POST variables before re-directing... Am researching now.

推荐答案

我没有回答,为什么$ _ POST不会在这个特定背景下(WooCommerce结帐下订单)工作的基本问题,但我相信我的语法很可能是正确的或接近的,因为相同或实质上,当我取代的形式后一得的方法同样的语法的工作,改变了变量$ _GET变量,从旧分离出来的新形式一。此外,也许是示意性,$ _ POST没有在第二种形式无论是工作,甚至在其新的位置。它只是偶然和绝望,我偶然发现,$ _GET没有工作。

I don't have an answer to the basic question as to why $_POST does not work in this particular context (WooCommerce checkout Place Order), but I believe that my syntax was likely correct or close, since the same or virtually the same syntax worked when I substituted a "get" method for "post" in the form, changed the variables to $_GET variables, and separated the new form from the old one. Also, perhaps indicatively, $_POST did not work in the second form either, even in its new position. It was only by chance and desperation that I happened to discover that $_GET did work.

由于安全性是不是真的在常规(对于一个已经登录的用户买票只是预订预订名)这一点值得关注,因为我相信,要求会在下面的$ _GET 3000个字符的限制,还是会有其他的变通办法对于后者,如果有必要,我会去的$ _GET的解决方案之前,除非我能找到(或有人只是告诉我!)在宇结帐的问题是什么。这似乎是一个Word preSS / WooCommerce问题,不是,因为我原来怀疑,一个PHP的问题。

Since security is not really a concern at this point in the routine (just booking reservations names for an already logged-in user buying tickets), and since I believe that the requests will come in below the $_GET 3000-character limits, or that there will be other workarounds for the latter if necessary, I'm going to go with the $_GET solution until and unless I am able to discover (or someone just tells me!) what the problem in Woo Checkout is. That would seem to be a WordPress/WooCommerce question, not, as I originally suspected, a PHP question.

我留下了一个新的任务,这将导致我问一个问题,这也是对话语preSS / PHP交界(就像这个网站有很多的时间,至少对我来说),不必做排序基于所得阵列的输出。我看到类似的问题提出的所有的时间,但还没有跨越这个特殊的运行被回答,但是这将是另一篇文章的话题,因为我不是presently肯定的回答是否是PHP(数组排序)或Word $ p $特定PSS-。如果任何人阅读此线程感觉就像短路我目前的计划,无论是通过预测我的问题还是,我向资源,将做的工作,请我的客人。

I am left with a new task that will lead me to ask a question that is also on the WordPress/PHP borderline (just like this site a lot of the time, at least for me), having to do with sorting the output based on the resultant array. I see similar questions posed all of the time, but have not yet run across this particular one being answered, but that will be the topic of another post, since I am not presently sure whether the answer will be more PHP (array sorting) or WordPress-specific. If anyone reading this thread feels like short-circuiting my current plans, either by anticipating my question or directing me to a resource that will do the job, please be my guest.

感谢所有那些谁提出的建议,谁至少基本确认没有在表面上是错误的语法,谁提供的调试建议。

Thanks to all those who made suggestions, who at least basically confirmed that nothing on the surface was wrong with the syntax, and who provided suggestions for debugging.

这篇关于PHP $ _POST变量数组的数组存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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