wp_session 变量被 $_POST 覆盖 [英] wp_session variables being overwritten by $_POST

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

问题描述

我正在尝试向 $wp_session 发布一个工作正常的表单 - 但是当我再次执行它时,它会覆盖我首先放在那里的数组,我需要数组像集合一样继续构建/购物篮.

I am trying to post a form to $wp_session which is working fine - however when I perform it again it overwrites the array that I have put there in the first place, I need the arrays to carry on building up like a collection / shopping basket.

我的表格:

<form class="form1" method="post" action="" id="form1">
<fieldset>
<ul>
        <label for="name">Exercise ID</label><span>
        <input type="text" name="ExerciseID" placeholder="Exercise ID" class="required" role="input" aria-required="true"/></span>

        <label for="name">Exercise Reps</label><span>
        <input type="text" name="Sets" placeholder="Sets" class="required" role="input" aria-required="true"/></span>

        <label for="name">Exercise Reps</label><span>
        <input type="text" name="Reps" placeholder="Sets" class="required" role="input" aria-required="true"/></span>

        <input  class="submit .transparentButton" value="Next" type="submit" name="Submit"/> 

</ul>
<br/>
</fieldset>
</form>

还有 php:

<?php

global $wp_session;

if (isset($_POST['Submit'])) {
 $wp_session['collection'] = array($POST['ExerciseID'],$_POST['Sets'],$POST['Reps']);

}

print_r($wp_session);

?> 

非常感谢.

推荐答案

要拥有一个购物篮,您必须将产品添加到一个数组中:

To have a basket, you have to add the products to an array:

<?php

global $wp_session;

if (isset($_POST['Submit'])) {
 $wp_session['collection'][] = array($_POST['ExerciseID'],$_POST['Sets'],$_POST['Reps']);

}

print_r($wp_session);

?> 

您可能希望按运动 ID 组织数组,以便您可以添加数量.我建议你创建一些对象,因为它们比数组更灵活

You may want to organize the array by ExerciseID, so you can add to the quantity. I would advice you to create some objects, as they will be more flexible than arrays

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

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