Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
formedit select multiple submit as POST or GET array
20/04/2009
11:50
Avatar
akremedy
California, USA
Member
Members
Forum Posts: 37
Member Since:
16/12/2008
sp_UserOfflineSmall Offline

I'm looking for some advice on how to handle <select multiple> submits from jqGrid.  I'm using formedit, version 3.5A2.

Again, this is a <select> field with multiple selections possible.  I'm using GET now for easier troubleshooting...if it matters.  Note that everything works fine when only one option is selected.  When multiple options are selected, only the last one is actually recognized on the backend (insert into db via php).  I see multiple selections get sent in the GET, but not as an array.

I have fixed this in two ways, but one breaks something else, and the other one requires a hack to grid.common.js.

Fix #1: in colModel, simply define the name of the <select> field as "name[]" - giving the square brackets makes it recognizable as an array.  The problem is that I dynamically set <options> into this field, and the function doesn't like field names with "[" or "]".

Fix #2: in grid.common.js, in the createEl function, append the square brackets to the field name:  options.name = options.name+"[]"; .   This actually works just fine in all of the testing that I've done, but wondering if there is a better way.

For reference:

colModel:

{name:"username",index:"username",width:500,align:'left',editable:true,edittype:'select',editoptions:{title:'Use <ctrl> left-click to select multiple people.',fixedsize:5,multiple:true,value:":"}}

the function that sets "username":

beforeShowForm:function(formid){
    $.ajax({
        url:".assets/admin_funcs.php?oper=selpplsel&fid="+fid+"&lid="+row_id,
        datatype:"script",
        mtype:"GET",
        success:function(response) {
            $('#username',formid).children().remove().end().html(response);
        }
    })
},

the php insert:

$pid = $_GET['username'];
$lid = $_GET['lid'];
foreach ($pid as $p) {
    $ins = "INSERT INTO people2links (pid,lid) VALUES('$p','$lid')";
    @mysql_query($ins) or die("error".mysql_error());
}

Thanks in advance,

Adam

22/04/2009
06:44
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

When we have a multiple select the data from select is posted separated with comma -  i.e. key1,key2...

Here is what I do in PHP suppose this is a filed myname then

$lid = $_GET['myname'];

$selects = explode(",",$lid);

This will return  array of type array('key1',key2,...);

Hope this helps

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

22/04/2009
12:10
Avatar
akremedy
California, USA
Member
Members
Forum Posts: 37
Member Since:
16/12/2008
sp_UserOfflineSmall Offline

Thanks Tony, that helps explain the reference I saw in the docs to the comma separated string...it just wasn't looking like that was how the data was posting.  I think I was dancing all around the simple solution here but didn't quite see it.

Thanks again!

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
89 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information