【问题标题】:$_POST Returns empty for multiple select box$_POST 为多选框返回空
【发布时间】:2010-04-14 18:15:30
【问题描述】:

好的,我正在通过 javascript 使用来自另一个选择框的选项填充我的多个选择框,如下所示:

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'] = ''(空字符串)。这里发生了什么???这应该有效,不是吗?

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

【问题讨论】:

  • 多选框中的项目是否标记为选中?
  • Opps,不,有没有办法在不选择它们的情况下获得它们?我明白你的意思,似乎当我选择它们时它就在那里。但无论他们是否被选中,我都需要将它们全部抓住。如何做到这一点?
  • 将它们的副本放在隐藏的输入中。
  • 你这么说很有趣,我也是这么想的,只是看起来有点草率。那好吧。无论如何谢谢:)

标签: php select post options


【解决方案1】:

我在简单的 HTML 中尝试了您的代码,它显示的 Array of 请求中的 layout_actions[]

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

所以我认为这就是为什么它不采用 select Box 的 Multiple 属性的原因

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    相关资源
    最近更新 更多