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
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-confirmand it works.I changed
to
Thanx all for your help