Feedback on Model Less forms as per official docs

if you copy the code direct from the 3.8 manual for creating a model less contact form you get this error:

Fatal error: Access level to App\Form\ContactForm::validationDefault() must be public (as in class Cake\Form\Form) in /www/sites/cake-bare/wwwroot/src/Form/ContactForm.php on line 10

if you change this line:
protected function validationDefault(Validator $validator)
to this
public function validationDefault(Validator $validator)

it works as instructed.

In version 4 you need to make a couple of changes
change this
protected function _buildSchema(Schema $schema)
to
protected function _buildSchema(Schema $schema): Schema

change this
protected function validationDefault(Validator $validator)
to this
public function validationDefault(Validator $validator): Validator

and this
protected function _execute(array $data)
to this
protected function _execute(array $data): bool

and again all is well.

Who / How do you advise that the docs are wrong?

1 Like

Hi!

Raise an issue here: https://github.com/cakephp/docs

Thanks