I'm reviewing the CakePHP documentation and, about forms and the FormHelper, I'm a bit confused about options to set default values for inputs.
From documentation:
Default option (here):
$options['default'] Used to set a default value for the input field. The value is used if the data passed to the form does not contain a value for the field (or if no data is passed at all).
Selected option (here):
$options['selected'] Used in combination with a select-type input (i.e. For types select, date, time, datetime). Set ‘selected’ to the value of the item you wish to be selected by default when the input is rendered:
Later, for FormHelper::select (here):
Creates a select element, populated with the items in $options, with the option specified by $attributes['value'] shown as selected by default.
The only thing of which I am sure, I have to use "checked" for checkboxes:
You cannot use default to check a checkbox - instead you might set the value in $this->request->data in your controller, or set the input option checked to true.
Is there anyone who can explain me clearly how to use these options? Thank you very much.
$this->request->data
in the controller. Instead "selected" can be used only for "select" inputs and the default value in this case can not be overwritten (?). Can this be so? For the third case, however, I do not understand. – Mirko Pagliai