Display a confirmation on Click on a submit button

53 Views Asked by At

I have a form with several submit buttons. When I click on one, I want to display a confirmation, and if ok the form is submited :

So I have the following code:

$(document).on('click', '[data-button-confirm]', function (e) {
     e.preventDefault();
     var $this = $(this);

     alertify.confirm('Confirmation', $(this).data('button-confirm'),
         function () {
             $this.parents('form').submit();
         },
         function () {
             $(this).blur();
         }
     ).set('labels', {
         ok: '<i class="fa fa-check"></i> Confirm',
         cancel: '<i class="fa fa-times"></i> Cancel'
     }).set('defaultFocus', 'cancel');
 });

But in my Symfony controller at the line of

if ($form->getClickedButton()->getName() === 'publish') {

I have the message

Call to a member function getName() on null
1

There are 1 best solutions below

0
Lolo On

With the help of @NicoHaase, I found a way to resolve my problem. I can't unbind the click event,then I remove the attribute data-button-confirm and it works.

I changed

 $this.parents('form').submit();

to

$this.removeAttr('data-button-confirm').click();

Thanx all for your help