This may seem obvious to some of you, but I'm really trying to find a direct answer. I usually googled and also read the CakePHP and API manual to answer the following question:
When you create an input, the following code creates the following outputs:
// in the view echo $this->Form->input('notes'); // resultant html <div class="input textarea"> <label for="notes">Notes</label> <textarea id="notes" rows="5" name="notes"></textarea> </div>
Note: this is consistent for most input types; and because it is consistent with this for formatting.
However, using the checkbox:
//In the view echo $this->Form->input('ticket_required', ['type' => 'checkbox'] ); // resultant HTML <div class="input checkbox"> <input type="hidden" value="0" name="ticket_required"> <label for="ticket-required"> <input id="ticket-required" type="checkbox" value="1" name="ticket_required"> Ticket Required</label> </div>
[Note: I understand the need / desire of the hidden field]
Now .. can it really not be an unusual requirement to just want the same format approach as any other standard input?
My question is how to get CakePHP to create a checkbox element like this:
// desired HTML <div class="input checkbox"> <input type="hidden" value="0" name="ticket_required"> <label for="ticket-required"> Ticket Required</label> <input id="ticket-required" type="checkbox" value="1" name="ticket_required"> </div>
To be clear: the order of the visible elements is the same as the other generated elements (the inscription in front of the entry and everything is enclosed in a wrapper div).
Please note: I tried the option 'nestedInput' => false . This actually eliminates the need to enter the checkbox completely from the div.
I donβt understand why this is not done this way ... but even if that were the case, I cannot understand why this is not an obvious issue for the documentation.
Ok, hope someone can help me here.
Thanks in advance.
Rick
elb98rm
source share