add 2 "checkbox" fields to any joomla form as below
<field
name="checkboxnovalue"
type="checkbox"
label="chekbox1"
/>
<field
name="checkboxcustomvalue"
type="checkbox"
label="checkbox2"
value="CUSTOM"
/>
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value
The value attribute is one which all inputs share; however, it serves a special purpose for inputs of type checkbox: when a form is submitted, only checkboxes which are currently checked are submitted to the server, and the reported value is the value of the value attribute. If the value is not otherwise specified, it is the string "on" by default.
Labels |
Added:
?
|
Checkboxes are a funny thing. The way they work is that if unchecked, the browser will not send anything.
So we should be storing nothing not a 0
That's probably why an unchecked box will appear blank.
As it should be but we store a value in the db of 0
I dont care about it being stored as On or 1
I do care that if checked and a value is defined then it should be stored in the db
Or am I misunderstanding it.
values stored as 0
Can't confirm this. If you're storing these fields in their own DB columns, maybe the columns have a default value of 0?
values stored as "On"
Can't confirm this either. Which form did you edit?
and "CUSTOM"
For this change value="CUSTOM"
to default="CUSTOM"
. See #22575.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-11-02 17:56:59 |
Closed_By | ⇒ | brianteeman |
Checkboxes are a funny thing. The way they work is that if unchecked, the browser will not send anything. If checked, the value is sent. Thus in Joomla, we have no way to check if the checkbox isn't sent because it was unchecked or because it wasn't there at all (due to overrides or custom field conditionals or ...). That's probably why an unchecked box will appear blank.As for the stored value, I think that could be changed to "on" for sure. But honestly I think "1" works better in PHP since you can evaluate it better, "on" is just a string without any special meaning in a computer language. Is there a reason you want it to be "on" (beside it is the actual value sent)?Ignore that, was reading the issue 180° wrong.