How to get a $_POST request from view module?

拥有回忆 提交于 2019-12-02 00:08:35

From the code in your pastebin link, you have two forms on the page. One starts on line 16, contains your user checkboxes, and then ends on line 61. Then the second starts on line 77 and ends on line 79. I'm guessing this the one being submitted by the javascript submit button you have on line 86.

Since you're submitting the second form, only its data gets posted. If you want everything to be submitted, it all needs to be in one form. Ideally you'd move the user checkboxes out of this template they're output as part of $form, but it might be tricky to keep them in a table layout that way, so the easier fix would be to move the table that contains the user checkboxes so it is output after the echo $this->formCollection($form);, but before that form ends with echo $this->form()->closeTag();. Get rid of the form tags you have on line 16 and 61, since you only want one form.

Edit: To fix the other issue, try changing your controller code to this:

if (!empty($_POST["users"])) {
    $userIDs = array();
    foreach ($_POST["users"] as $selectedUser) {
        if (is_numeric($selectedUser) && $selectedUser > 0) {
            $userIDs[] = $selectedUser;
        }
    }

    if (count($userIDs) > 0) {
        $users = $this->getUserTable()->fetchAll(false, "id IN (".implode(', ', $userIDs).")");
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!