Form submit checkbox array

QuestionsForm submit checkbox array
Richard asked 11 years ago

I am enclosing a grid within a form. Normally, I would select records using checkboxes like this:

input name="itemid[]" value="12" type="checkbox"

That way I can easily process the array with php like

foreach $itemid as $value{
etc etc

So my question is: How can I name the checkboxes like that?

3 Answers
Abu Ghufran answered 11 years ago

It is not doable now as it need major changes in how jqgrid javascript component is built.
What you can do is to get all selected checkboxes id using following js code and post them separately.

<script>
var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); // returns null if no row is selected (single row)
var selr = jQuery('#list1').jqGrid('getGridParam','selarrrow'); // array of id's of the selected rows when multiselect options is true. Empty array if not selection
</script>

Richard answered 11 years ago

I have done it before with this component. Like this:

colNames:['Description','Inclusions','Code','RRP'],
colModel :[
{formatter: cboxFormatter,name:'supplier_description', index:'supplier_description', width:335, align:'left'},
{name:'supplier_inclusions', index:'supplier_inclusions', width:610, align:'left'},
{name:'supplier_code', index:'supplier_code', width:230, align:'left'},
{name:'sale_price', index:'sale_price', width:90, align:'right', sortable:false}
],

and then

function cboxFormatter(cellvalue, options, rowObject)
{
return '<input type="checkbox" name="itemid[]" value="'+options.rowId+'" onclick="test('+options.rowId+',this.checked);"/> '+cellvalue;
}

I just have trouble "translating" this into my current setup with phpgrid.

Abu Ghufran answered 11 years ago

You can use it in following manner …

$col = array();
$col["title"] = "Closed";
$col["name"] = "closed";
$col["width"] = "50";
$col["editable"] = true;
$col["edittype"] = "checkbox"; // render as checkbox
$col["editoptions"] = array("value"=>"1:0"); // with these values "checked_value:unchecked_value"
$col["formatter"] = "function(cellvalue, options, rowObject){ return cboxFormatter(cellvalue, options, rowObject);}";

<script>
function cboxFormatter(cellvalue, options, rowObject)
{
return '<input type="checkbox" name="itemid[]" value="'+options.rowId+'" onclick="test('+options.rowId+',this.checked);"/> '+cellvalue;
}
</script>
<div style="margin:10px">
<?php echo $out?>
</div>

Your Answer

7 + 5 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?