返回一个数组以发布到PHP中的$ _SESSION

时间:2014-01-05 23:38:34

标签: php arrays session session-variables

我有一个使用Checkbox输入的表单,我将它们全部命名为数组名称=“benefits []”

这被填充到一个jquery中,作为Chain Selects的一部分使用。

我的问题是如何将数组放入$ _SESSION以便选择哪个复选框我可以在我网站中另一个页面的另一个输入框中使用它?

<input type="checkbox" class="comOne" name="benefits[]" value="Pension credit" id="pension_credit" /> 
Pension credit 
<a href="#" class="showBenefitInfo" data-value="Pension credit is a top-up to the state pension and is a benefit that must be applied for if your state pension is below a certain amount.">[More...]</a>

道歉,如果我不应该这样做,不确定你是否可以上传文本框,无论如何这是复选框的整段代码。如果需要,我可以粘贴整个表格。

                            <div class="row">
                                <div class="col-md-5">  
                                    <label class="checkbox">
                                        <input type="checkbox" class="comOne" name="benefits[]" value="Pension credit" id="pension_credit" /> Pension credit <a href="#" class="showBenefitInfo" data-value="Pension credit is a top-up to the state pension and is a benefit that must be applied for if your state pension is below a certain amount.">[More...]</a>
                                    </label>
                                </div>
                                <div class="col-md-5">  
                                    <label class="checkbox">
                                        <input type="checkbox" class="comOne" rel="CTC"  name="benefits[]" value="Child tax credit" id="child_tax_credit" /> Child tax credit <a href="#" class="showBenefitInfo" data-value="Child Tax Credit is a benefit that must be applied for, it is not the same as Child Benefit. An up-to-date Child Tax Credit award notice must be available to show the surveyor to proceed with your application. ">[More...]</a>
                                    </label>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-5">  
                                    <label class="checkbox">
                                        <input type="checkbox" class="comOne" rel="ISJSA" name="benefits[]" value="Income support" id="income_support" /> Income support <a href="#" class="showBenefitInfo" data-value="Income support is a means-tested benefit and is primarily received by single parents with a child under 5.">[More...]</a>
                                    </label>
                                </div>
                                <div class="col-md-6">  
                                    <label class="checkbox">
                                        <input type="checkbox" class="comOne" rel="ISJSA" name="benefits[]" value="Job seekers allowance" id="job_seekers_allowance" /> Income based job seekers allowance <a href="#" class="showBenefitInfo" data-value="You must be in receipt of INCOME based job seekers allowance. This will be confirmed on your award notice (you will see printed on your letter: 'This assessment is based on how much the law says you need to live on').">[More...]</a>
                                    </label>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-5">  
                                    <label class="checkbox">
                                        <input type="checkbox" class="comOne" rel="WTC" name="benefits[]" value="Working tax credit" id="working_tax_credit" /> Working tax credit <a href="#" class="showBenefitInfo" data-value="You will need to have you Working Tax Credit award notice available (this will be the same as Child Tax Credit award notice if both are being received). Page 2 and 3 will confirm your household income and this MUST be less than &pound;15,860 to qualify.">[More...]</a>
                                    </label>
                                </div>
                                <div class="col-md-6">  
                                    <label class="checkbox">
                                        <input type="checkbox" class="comOne" rel="ESA" name="benefits[]" value="Income related employment" id="income_related" /> Income related employment and support allowance <a href="#" class="showBenefitInfo" data-value="Also known as ESA, Employment and Support Allowance must be INCOME related and NOT contribution based. This will be confirmed on your ESA award notice.">[More...]</a>
                                    </label>
                                </div>
                            </div> 
                            <div class="row">
                                <hr>
                                    <div class="col-md-12">
                                        <label class="checkbox">
                                            <input type="checkbox" class="comOne" name="benefits[]" value="I do NOT receive any of the above benefits" id="no_benefits" /> I do NOT receive any of the above benefits 
                                        </label>
                                    </div>
                                </hr>
                            </div>

1 个答案:

答案 0 :(得分:1)

这很直接:

$_SESSION['benefits'] = $_POST['benefits'];