Customizing the Form Page

Customizing Fields

Fields may be specified via the scaffold.fields configuration key. By default, this will contain a list of all columns associated with the Table being in scope. To limit the fields used, simply specify an array of fields.

$action = $this->Crud->action();
$action->config('scaffold.fields', ['title', 'description']);

You may also specify an options array. For forms, CrudView makes use of the FormHelper::inputs() method and will pass your array values as options when generating the output.

$action = $this->Crud->action();
$action->config('scaffold.fields', [
    'title',
    'thread_id' => [
        'type' => 'text'
    ],
    'featured' => [
        'checked' => 'checked'
    ]
]);

Setting options for specific fields

If you wish to use the default automatic field population functionality but want to specify settings for a few of the fields, you can use the scaffold.field_settings configuration key:

$action = $this->Crud->action();
$action->config('scaffold.field_settings', [
    'title' => [
        // options here
    ]
]);

Removing Fields from output

You may also use the scaffold.fields_blacklist configuration key to remove fields from the output if you are using the default automatic field population functionality:

$action = $this->Crud->action();
$action->config('scaffold.fields_blacklist', ['created', 'modified']);

Grouping fields in tabs

You can group the form fields in tabs using the scaffold.form_tab_groups configuration key:

$action = $this->Crud->action();
$action->config('scaffold.form_tab_groups', [
    'First Tab Header' => ['field_1', 'field_2'],
    'Second Tab Header' => ['field_3', 'field_4'],
]);

If there are fields which are not listed under any group they will be automatically shown under 1st tab with header Primary. You can customize the primary group’s name using scaffold.form_primary_tab config.

$action = $this->Crud->action();
$action->config('scaffold.form_primary_tab', 'Key Info');

Form Submission

Form Submission Redirect

By default, the Crud plugin will redirect all form submissions to the controller’s index action. This can be changed by setting the _redirect_url view variable:

$this->set('_redirect_url', ['action' => 'home']);

Form Submission Check

By default, closing the a form page in your browser will result in lost data. However, you may force a user prompt by enabling dirty form checks using the scaffold.form_enable_dirty_check configuration key:

$action = $this->Crud->action();
$action->config('scaffold.form_enable_dirty_check', true);

Submit Buttons

Changing the Submit Button Text

You can change the submit button text from it’s default using the scaffold.form_submit_button_text configuration key.

$action = $this->Crud->action();
$action->config('scaffold.form_submit_button_text', _('Submit'));

Modifying the Default Extra Buttons

By default, we should the following extra buttons for forms:

  • Save & continue editing: Results in a form submission

  • Save & create new: Results in a form submission

  • Back: A link to the index page

To use the defaults, you may either omit the configuration key or set it to true:

$action = $this->Crud->action();
$action->config('scaffold.form_submit_extra_buttons', true);

You can also customize this by using the scaffold.form_submit_extra_buttons configuration key as follows:

$action = $this->Crud->action();
$action->config('scaffold.form_submit_extra_buttons', [
    [
        'title' => __d('crud', 'Save & continue editing'),
        'options' => ['class' => 'btn btn-success btn-save-continue', 'name' => '_edit', 'value' => true],
        'type' => 'button',
    ],
    [
        'title' => __d('crud', 'Save & create new'),
        'options' => ['class' => 'btn btn-success', 'name' => '_add', 'value' => true],
        'type' => 'button',
    ],
    [
        'title' => __d('crud', 'Back'),
        'url' => ['action' => 'index'],
        'options' => ['class' => 'btn btn-default', 'role' => 'button', 'value' => true],
        'type' => 'link',
    ],
]);

Specified values will override the defaults, and will be output in the order specified.

Modifying the Default Extra Left Buttons

By default, extra buttons appear on the right-hand side of forms. The left-hand side is managed separately, and will show the following by default

  • Delete: An embedded postLink for deleting the current entity. This only appears on the pages that are rendered via EditAction.

To use the defaults, you may either omit the configuration key or set it to true:

$action = $this->Crud->action();
$action->config('scaffold.form_submit_extra_left_buttons', true);

You can also customize this by using the scaffold.form_submit_extra_left_buttons configuration key as follows:

$action = $this->Crud->action();
$action->config('scaffold.form_submit_extra_left_buttons', [
    [
        'title' => __d('crud', 'Save & continue editing'),
        'options' => ['class' => 'btn btn-success btn-save-continue', 'name' => '_edit', 'value' => true],
        'type' => 'button',
    ],
]);

Disabling the Default Extra Buttons

Rather than modifying the default extra buttons, you can also disable them completely:

$action = $this->Crud->action();
$action->config('scaffold.form_submit_extra_buttons', false);

Disabling the Default Extra Left Buttons

Disabling the default left extra buttons can also be done in a similar fashion:

$action = $this->Crud->action();
$action->config('scaffold.form_submit_extra_left_buttons', false);

Available Viewblocks

The following custom view blocks are available for use within forms:

  • form.sidebar: Rendered on the side of a form. Will also change the form width.

  • form.before_create: Rendered before FormHelper::create() is called.

  • form.after_create: Rendered after FormHelper::create() is called.

  • form.before_end: Rendered before FormHelper::end() is called.

  • form.after_end: Rendered after FormHelper::end() is called. Used by embedded Form::postLink() calls.

Available Elements

All the CrudView templates are built from several elements that can be overridden by creating them in your own src/Template/Element folder. The following sections will list all the elements that can be overridden for each type of action.

In general, if you want to override a template, it is a good idea to copy the original implementation from vendor/friendsofcake/crud-view/src/Template/Element

action-header

Create src/Template/Element/action-header.ctp to have full control over what is displayed at the top of the page. This is shared across all page types.

form/buttons

Create src/Template/Element/form/buttons.ctp to change what is displayed for form submission. You can expect the $formSubmitButtonText and $formSubmitExtraButtons variables to be available

  v: latest
Versions
latest
stable
docs
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds
Downloads
On GitHub
View
Edit

Free document hosting provided by Read the Docs.