Search code examples
cakephp-3.0confirmation

Confirm message not working on postLink with icon


I need some help with a postLink created with FormHelper in CakePHP 3. The normal postLink works just fine like this:

<?= $this->Form->postLink(__('Delete'), 
    ['action' => 'delete', $member->id],
    ['confirm' => __('Are you sure, you want to delete {0}?', $member->name)]) ?>

But when I try to use a font-awesome icon / i-tag instead of the text link, the confirmation message is not showing up anymore. The icon itself is showing correctly and the action still works fine, just the message is not working.

I used the following posts for help, but the examples in the answers there are not working for me:

CakePHP equivalent of html code

CakePHP delete confirmation

I tried these two approaches:

<?= $this->Form->postLink('<i class="fa fa-trash"></i> ',
    ['action' => 'delete', $member->id], 
    ['escape' => false], 
    ['confirm' => __('Are you sure, you want to delete {0}?', $member->name)]) ?>


<?= $this->Form->postLink(
        $this->Html->tag('i', '', ['class' => 'fa fa-trash']), 
                    ['action' => 'edit', $member->id],
                    ['escape' => false],
                    ['confirm' => __('Are you sure you want to delete {0}?', $member->name)]); ?>

I'm still very new to CakePHP and tried to look this up in the book, but that did not help me. I also tried the exact syntax as shown in the SO links above, which seemingly worked for some others...but the confirmation message is still not working for me.

What am I doing wrong here?


Solution

  • escape and confirm options should be in the same array. Function postLink() looks like this:

    postLink(string $title, mixed $url = null, array $options =[])
    

    So working code for you will be:

    <?= $this->Form->postLink('<i class="fa fa-trash"></i> ',
        ['action' => 'delete', $member->id], 
        [
            'escape' => false,
            'confirm' => __('Are you sure, you want to delete {0}?', $member->name)
        ]
    ) ?>