How to get a $_POST request from view module?

I want to get the checkboxes from a table in a view module, but I can't get it to work. This is the table:

<form action="" method="post"> <TABLE id="dt_basic" class="table table-striped table-bordered table-hover dataTable"> <THEAD> <TR> <TH></TH> <TH>ID</TH> <TH>Client</TH> <TH>User</TH> <TH>Role</TH> <TH>Projects</TH> </TR> </THEAD> <TBODY> <?php /* @var $item Admin\Model\User */ foreach ($this->users as $item) { ?> <TR> <TD class='admin'><input type="checkbox" name="users[<?php echo $item->id; ?>]" value=<?php echo $item->id; ?> checked/></TD> <TD class='admin c'><?= $item->id ?></TD> <TD class='admin'><?= $item->getClientObject() ?></TD> <TD class='admin'> <img src="<?= $item->getAvatarPath() ?>" alt="me" class="online avatar"/> <a title='details' href='/admin/user/detail/id/<?= $item->id ?>'><?= $item->name . " " . $item->surname ?> </a> </TD> <TD class='admin'><?= $item->getRoleObject() ?></TD> <TD class='admin'> <a title='projects' class='btn btn-default btn-sm' href='/admin/user/project/id/<?= $item->id ?>'><i class='fa fa-icon-fix fa-briefcase'></i></a> <? foreach ($this->projects[$item->id] as $i => $project) { echo $project->getName(); if ($i != sizeof($this->projects[$item->id]) - 1) echo " • "; } ?> </TD> </TR> <?php } ?> </TBODY> </TABLE> </form>

The whole .phtml : http://pastebin.com/8paJZgjb

I want to get the users[] array and use its elements inside the controller, but I can't find a way to get it. Here's what I've tried so far:

if (!empty($_POST["users"])) { foreach (($_POST["users"]) as $selectedUsers) { $users = $this->getUserTable()->fetchAll(false, "id=" . $selectedUsers); } } else { $this->cache->error = "Please choose at least one user."; return $this->view; }

The whole function: http://pastebin.com/pE4afemx

...but apparently it's empty. var_dump shows the elements from the mailing form, but no sign of the users:

array (size=2) 'subject' => string 'hello' (length=5) 'message' => string 'message' (length=7)

Any suggestions ?

-------------Problems Reply------------

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).")");
}

Category:php Views:3 Time:2018-04-13

Related post

  • C# how to get list of data from view into controller in MVC 3 2011-10-09

    Please anyone tell me, how to get all list of modified data from view into controller in mvc3 at the time of page submit. there are three columns in my view emp_id, emp_name and check box i only want to get only checked data into controller public cl

  • How to get an Ajax request from an external server using client side JavaScript 2010-12-08

    I'm trying to write a utility in my blog system as a post. The limitations are that I can not run any server side code. I can only run client side (JavaScript) code. I would like to send a request to an external domain and parse that result. For exam

  • How to get a complete request from a NSURLRequest? 2012-02-01

    Is there any way to get the actual data that will be sent when a NSURLConnection sends a NSURLRequest? Right now I'm mainly interested in looking at HTTP and HTTPS requests, but since NSURLRequest works for many protocols, it seems like there ought t

  • How to get a message request from its sequence number? 2010-01-25

    Given a sequence number, I need to find the corresponding request message string. I can't find a way to it easily do that with quickFix lib. To be short, I've had the idea to use the FileStore "body" file to help me retrieve the message request strin

  • how to get the base url from jsp request object? 2011-06-07

    How to get the base url from the jsp request object? http://localhost:8080/SOMETHING/index.jsp, but I want the part till index.jsp, how is it possible in jsp? --------------Solutions------------- So, you want the base URL? You can get it in a servlet

  • How to get a remote JPG from a URL using USER and Password? 2012-03-15

    i want to get a remote JPG file from a URL and have it into a Bitmap. I'm developing for Android, i have internet on the phone and internet permission on the manifest. The problem is that the URL needs a user and a password. I know how to get a remot

  • How to get latitude and longitude from address on Android? 2012-04-14

    I am beginner in Android and I am working to create the Google Map which is able to mark the specific location from address. For now, my following code is able to mark "empire state building" but nothing others..:< I want to know how to get latitu

  • how to get the button value from jsp to servlet 2010-05-26

    how to get the button value from jsp to servlet in jsp: <input type=button name=bt value=gi onclick="document.frm.submit();"></input> and in servlet like that: String gi =request.getParameter("bt"); System.out.print("button value" +gi); r

  • How to get the message body from PHPMailer? 2011-08-23

    I use PHPMailer to send email via SMTP. It works, but it doesn't save the sent emails in sent items. I want to make to sent emails in the sent items, any idea? I know can use imap_append function to achieve it. But, how to do that? The PHPMailer seem

  • How to get the IP address from a visitor (also if behind a Proxy) 2011-09-07

    Possible Duplicate: Client IP using C# I use ASP.net and C# and I would like to know how to get the IP address from a visitor on a page. I would like to see an example of code that retrieves the IP address and also will be able to show if an IP was b

  • How to get the selected value from a WPF ComboBox DataTemplate 2011-11-25

    I want to find out how to get the selected value from a combobox column in a listview with a gridview view or even a datagrid. The xaml will look like this: <ListView Name="lstPicker" ItemsSource="{Binding}" SelectionMode="Single" Margin="6" >

  • How to get the file path from URI? 2012-01-16

    This question already has an answer here: Get filename and path from uri from mediastore 10 answers Please find my code below. I need to get the file path of the pdf document, selected by the user from SDcard. The issue is that the URI.getPath() retu

  • how to get utf-8 data from query string in JSP 2012-02-25

    I want to get utf-8 data from query string in jsp page therefore I have written following simple JSP page But I am getting garbaage instead of utf-8 data. I want to know how to get utf-8 data from query string in JSP <%@ page language="java" conte

  • How to call codeigniter controller function from view 2012-04-03

    How to call codeigniter controller function from view? When i call the function in a controller, get a 404 page. --------------Solutions------------- Codeigniter is an MVC (Model - View - Controller) framework. It's really not a good idea to call a f

  • how to get editable text value from database in android 2012-04-03

    I am fetching the text from database and append to edit text.it display all text in edittext.now i am changing some text in editext .i want what i am changed text in editext that values i want print this my listview code JSONArray json = jArray.getJS

  • Using MODI how to get images and table from scanned document images files into text document files. 2012-09-03

    Dear ALL, Using MODI how to get images and table from scann document images files into text document files. I am using C#.net to develop an application. Thanks Laxman --------------Solutions------------- The issue you posted would be better suited in

  • How to get users circle details from google circle API in android 2014-08-12

    I am using google circle API. but i am not able to find how to get users circle details from it in android. --------------Solutions------------- There are examples in the documentation here. Use the Plus.PeopleApi.loadVisible method to make an asynch

  • How to get attribute and values from xml in android through libxml2 2009-08-10

    How to get attribute and values from xml in android through libxml2 in android give me sample code ........ i need to get value type and tag for hello guys vodafone and populate a class objet which has same data member . like this ... type =string va

  • How to get main window handle from process id? 2009-12-11

    How to get main window handle from process id? I want to bring this window to the front. It works well in "Process Explorer". --------------Solutions------------- I don't believe Windows (as opposed to .NET) provides a direct way to get that. The onl

  • how to get top n rows from a table where value of n is passed at run-time? 2010-02-14

    How to get top n rows from a table where value of n is passed at run-time? --------------Solutions------------- In SQL Server 2005 and beyond you can actually parameterise the top command. The code below is from MSDN USE AdventureWorks; GO DECLARE @p

  • How to get the perticluar image from large set images in one image using css 2010-03-11

    How to get the perticluar image from large set images in one image using css e.g. Jquery ui icons having one large image but using css class it retrives only perticlar image icon. --------------Solutions------------- Firstly, you create approporiate

  • How to get the next row from the Database table? 2010-04-28

    How to get the next row from the Database table? Such that the row might be incremented row that is if structure has a field called "id" then the row can be id++ or very next incremented row, but it may also b any other id containing row (NOT VERY NE

  • How to get friends Email id from facebook using asp.net code 2010-04-29

    How to get friends Email id from facebook using asp.net code --------------Solutions------------- You can use facebook API: API: http://wiki.developers.facebook.com/index.php/User:C_Sharp http://wiki.developers.facebook.com/index.php/User:ASP.NET SDK

  • how to get all column value from sphinx by configuration file php 2010-06-16

    i want to know how to get all column value from table using sphinx search... i have configuration file, that file can get only one field from table. but i need all field value. where will i modify for getting all field from table. thanks and advance.

  • How to get not truncated text from IUITextField 2010-07-12

    I have created a custom column header renderer for my AdvancedDataGrid which has a text and a little button inside. Everything works just fine, until a moment when I have to return a headerText by the button click. Since my custom renderer is an exte

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.188 (s). 11 q(s)