CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.2 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.2
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class Form

Form abstraction used to create forms not tied to ORM backed models, or to other permanent datastores. Ideal for implementing forms on top of API services, or contact forms.

Building a form

This class is most useful when subclassed. In a subclass you should define the _buildSchema, _buildValidator and optionally, the _execute methods. These allow you to declare your form's fields, validation and primary action respectively.

You can also define the validation and schema by chaining method calls off of $form->schema() and $form->validator().

Forms are conventionally placed in the App\Form namespace.

Namespace: Cake\Form

Property Summary

  • $_errors protected
    array

    The errors if any

  • $_schema protected
    Cake\Form\Schema

    The schema used by this form.

  • $_validator protected
    Cake\Validation\Validator

    The validator used by this form.

Method Summary

  • __debugInfo() public

    Get the printable version of a Form instance.

  • _buildSchema() protected

    A hook method intended to be implemented by subclasses.

  • _buildValidator() protected

    A hook method intended to be implemented by subclasses.

  • _execute() protected

    Hook method to be implemented in subclasses.

  • errors() public

    Get the errors in the form

  • execute() public

    Execute the form if it is valid.

  • schema() public

    Get/Set the schema for this form.

  • validate() public

    Used to check if $data passes this form's validation.

  • validator() public

    Get/Set the validator for this form.

Method Detail

__debugInfo() ¶ public

__debugInfo(): array

Get the printable version of a Form instance.

Returns
array

_buildSchema() ¶ protected

_buildSchema(Cake\Form\Schema $schema): Cake\Form\Schema

A hook method intended to be implemented by subclasses.

You can use this method to define the schema using the methods on Cake\Form\Schema, or loads a pre-defined schema from a concrete class.

Parameters
Cake\Form\Schema $schema

The schema to customize.

Returns
Cake\Form\Schema

_buildValidator() ¶ protected

_buildValidator(Cake\Validation\Validator $validator): Cake\Validation\Validator

A hook method intended to be implemented by subclasses.

You can use this method to define the validator using the methods on Cake\Validation\Validator or loads a pre-defined validator from a concrete class.

Parameters
Cake\Validation\Validator $validator

The validator to customize.

Returns
Cake\Validation\Validator

_execute() ¶ protected

_execute(array $data): bool

Hook method to be implemented in subclasses.

Used by execute() to execute the form's action.

Parameters
array $data

Form data.

Returns
bool

errors() ¶ public

errors(): array

Get the errors in the form

Will return the errors from the last call to validate() or execute().

Returns
array

execute() ¶ public

execute(array $data): bool

Execute the form if it is valid.

First validates the form, then calls the _execute() hook method. This hook method can be implemented in subclasses to perform the action of the form. This may be sending email, interacting with a remote API, or anything else you may need.

Parameters
array $data

Form data.

Returns
bool

schema() ¶ public

schema(Cake\Form\Schema|null $schema = null): Cake\Form\Schema

Get/Set the schema for this form.

This method will call _buildSchema() when the schema is first built. This hook method lets you configure the schema or load a pre-defined one.

Parameters
Cake\Form\Schema|null $schema optional

The schema to set, or null.

Returns
Cake\Form\Schema

validate() ¶ public

validate(array $data): bool

Used to check if $data passes this form's validation.

Parameters
array $data

The data to check.

Returns
bool

validator() ¶ public

validator(Cake\Validation\Validator|null $validator = null): Cake\Validation\Validator

Get/Set the validator for this form.

This method will call _buildValidator() when the validator is first built. This hook method lets you configure the validator or load a pre-defined one.

Parameters
Cake\Validation\Validator|null $validator optional

The validator to set, or null.

Returns
Cake\Validation\Validator

Property Detail

$_errors ¶ protected

The errors if any

Type
array

$_schema ¶ protected

The schema used by this form.

Type
Cake\Form\Schema

$_validator ¶ protected

The validator used by this form.

Type
Cake\Validation\Validator
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs