Search code examples
formscakephp-2.1

Delete button/link inside form


I have a form for my sessions card, and I would like to configure the delete link. I think that I could do it with a get request at the end of each row.. However, in cakephp 2.. it "suggests" that its better to use a post request.

That's ok :

<?php
    echo $this->Form->postLink(
                    '<button class="btn btn-danger">
                         <i class="icon-trash icon-white"></i>
                     </button>',
                    array(
                          'action'   => 'deleteBasket', $plaque['id']
                          ),
                    array(
                          'class'    => 'tip',
                          'escape'   => false, 
                          'confirm'  => 'Are you sure ?'
                         ));
?>

Except that when I use this code, it generate a form inside my form so when I submit it's screwed up. I can't put this outside of my row . Any ideas ?


Solution

  • Reading the docs, http://api20.cakephp.org/class/form-helper#method-FormHelperpostLink

    This method creates a <form> element. So do not use this method inside an existing form. Instead you should add a submit button using FormHelper::submit()