View Full Version : [2.0b1][CLOSED] Checkbox $_POST data bug or by design?

29 Oct 2007, 8:33 AM
I've notice that a check box doesn't submit anything unless it's checked.
e.g. a checked check box submits:

$_POST['checkbox name'] == "on" and an unchecked check box submits:

null (by 'null' I mean the $_POST array is completely blank)

which is fine by itself but the problem comes in with a tabbed form. In a tabbed form, only the items in tabs a user views are submitted. Because of this and how checkbox submits, in a tabbed form you cannot tell whether the user unchecked the checkbox in a tab or they just never clicked on that tab to view it.

So is this a bug or am I just missing something?

29 Oct 2007, 8:53 AM
this is standard HTML behaviour.

I use my own submit action which works around this problem. It sends all values as params - so for every field getValue() is called to get the value (not the dom-input direclty)
This is useful for Checkbox, Date and ComboBox.

file-uploads don't get touched (as they won't work else)

Vps.SubmitAction = function(form, options){
Vps.SubmitAction.superclass.constructor.call(this, form, options);

Ext.extend(Vps.SubmitAction, Ext.form.Action.Submit, {
run : function(){
if (!this.options.params) this.options.params = {};

//manually add date-value and checkbox-state and clear name to submit it only once
this.form.items.each(function(field) {
if (Ext.form.DateField && field instanceof Ext.form.DateField && field.getValue() instanceof Date) {
this.options.params[field.getName()] = field.getValue().dateFormat("Y-m-d");
} else if (Ext.form.Checkbox && field instanceof Ext.form.Checkbox) {
if (field.getValue()) {
this.options.params[field.getName()] = 1;
} else {
this.options.params[field.getName()] = 0;
} else if (field.rendered && field.el.dom.type == 'file') {

29 Oct 2007, 9:24 AM
Thanks for the help.

You're right that is standard HTML behavior. For some reason I thought an unchecked checkbox submitted something in standard HTML.

Thanks to your code help I was able to fix the problem. :)

29 Oct 2007, 11:13 AM
Use the inputValue config to Checkbox to set the value that you want to be submitted if checked.