4

Migrating CakePHP 2.x to 3.x, in submit button CakePHP 2.x have after and before attribute, but that is not working on CakePHP 3.x.

<?php
 echo $this->Form->submit(__('Save'), array(
    'div' => 'form-actions',
    'class' => 'btn btn-large btn-primary btn-save',
    'data-loading-text' => 'Please Wait...',
    'after' => '    ' . $this->Html->link(__('Cancel'), array('admin' => true, 'action' => 'index'), array('class' => 'btn btn-large'))
)); ?>

Please help me, how to get the after button in submit button using CakePHP 3.x?

Oops D'oh
  • 941
  • 1
  • 15
  • 34
sree s
  • 61
  • 2

1 Answers1

2

You could use a custom template when you create your submit. To use a custom template, you need to use the FormHelper::input with 'type' => 'submit' method instead of the FormHelper::submit method.

You want to modify the container template (submitContainer) to insert your link (and add the form-actions class because the div option does not exist in CakePHP 3):

$after = $this->Html->link(__('Cancel'), 
    ['admin' => true, 'action' => 'index'], 
    ['class' => 'btn btn-large']
);
$this->Form->input (__('Save'), [
    'type'  => 'submit',
    'class' => 'btn btn-large btn-primary btn-save',
    'data-loading-text' => 'Please Wait...',
    'templates' => [
        'submitContainer' => '<div class="submit form-actions">{{content}}'.$after.'</div>'
    ]
]);

There is a way to add additional template variables to some containers template (e.g. inputContainer), unfortunately as of now (CakePHP 3.1.6) it does not work for the submitContainer (this is not really documented, but looking at the source of FormHelper you can see that for submit input, you never reach the relevant code).

Holt
  • 36,600
  • 7
  • 92
  • 139