$ _POST为多个选择框返回空

时间:2010-04-14 18:15:31

标签: php select post options

好的,我正在填写我的多选框,其中包含来自另一个选择框的选项,如下所示:

function addAction()
{
    var actions = document.getElementById("actions");
    var action_list = document.getElementById("actions_list");
    var opt = document.createElement("option");
    for (var i=0; i<action_list.options.length; i++)
    {
        if (action_list.options[i].text == actions.options[actions.selectedIndex].text)
            return;
    }
    action_list.options.add(opt);
    opt.text = actions.options[actions.selectedIndex].text;
    opt.value = actions.options[actions.selectedIndex].value;
}

function removeActions()
{
    var action_list = document.getElementById("actions_list");
    for(i=action_list.options.length-1;i>=0;i--)
    {
        if (action_list.options[i].selected)
            action_list.remove(i);
    }
}

现在,当我通过上面的JS将1个选择框中的值添加到此1中时,以下$layout_actions[]返回EMPTY:

echo '<select id="actions_list" name="layout_actions[]" multiple style="height: 128px; width: 300px;', (isset($context['layout_error']['no_actions']) ? ' border: 1px solid red;' : ''), '">';
                            foreach($context['current_actions'] as $cur_action)
                                echo '
                                    <option value="', $cur_action, '">', $cur_action, '</option>';  

        echo '
                                    </select>

简而言之,my $_POST['layout_actions'] = ''(空字符串)。这里发生了什么???这应该有效,不应该吗?

请帮帮我... argg。我知道正在添加元素,因为我可以看到它们在单击“添加”按钮时从1个选择框到多个选择框,但是当我发布表单时,layout_actions返回空。

1 个答案:

答案 0 :(得分:0)

我在简单的HTML中尝试了你的代码,它正在显示数组 请求中的layout_actions []

我看到你在单引号中使用Variable $ context ....

所以我认为这就是为什么它没有选择Box的多重属性

 echo '<select id="actions_list" name="layout_actions[]" multiple style="height: 128px; width: 300px;', (isset($context['layout_error']['no_actions']) ? ' border: 1px solid red;' : ''), '">';