Forum


11:50

16/12/2008

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":
$.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:
$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
06:44

Moderators
30/10/2007

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.
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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66