Tuesday, February 22, 2022

[FIXED] CakePHP 3.0 - Post Link - adding classes removes alert confirmation functionality

Issue

When I add the class array to the postLink, the confirm alert stops working. I have moved the class array into different positions but within the postLink but nothing seems to work.

<?= $this->Form->postLink(__('Delete'),
['controller' => '<%= $details['controller'] %>', 'action' => 'delete', <%= $otherPk %>],
['class' => 'btn btn-danger btn-sm'],
['confirm' => __('Are you sure you want to delete # {0}?', <%= $otherPk %>)]) %>

The above code will add the right classes to the link, but the confirmation doesn't work, it just deletes the entry right away.


Solution

the confirm message and the other html options like class go in the same array

<?= $this->Form->postLink(__('Delete'),
    ['controller' => '<%= $details['controller'] %>', 'action' => 'delete', <%= $otherPk %>],
    ['class' => 'btn btn-danger btn-sm'],'confirm' => __('Are you sure you want to delete # {0}?', <%= $otherPk %>)]) %>


Answered By - arilia

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.