javascript - In form data, pass info about which button was clicked -- after confirmation modal -


the click event on submit button triggers confirmation modal.

when user clicks on confirmation button, form sent without original submit button data, need.

simplified code:

<form action="/action" method="post">     <!-- inputs -->     <button type="submit" name="foo" class="with-confirmation-modal" /> </form>  <script> $(document).on('click', '.with-confirmation-modal', function() {     $form = $(this).closest('form');     $modal = $('#modal');     $modal.on('click', 'button[type=submit]', function() {         // form sent without info button         // clicked prior modal         $form.submit();         return false;     });     $modal.modal('show');     return false; }); </script> 

what's way deal ?

when post form clicking on

<button type="submit" name="foo" /> 

data posted includes name of button :

...&foo=&...  

this behaviour broken confirmation popup. here simulate adding hidden input name of clicked button before calling $form.submit().

<script> $(document).on('click', '.with-confirmation-modal', function() {     var $clickedbtn = $(this);     var $form = $clickedbtn.closest('form');     $modal = $('#credit-headsup-modal');     $modal.on('click', 'button[type=submit]', function() {         $(this).parent('.btn-wrapper').addclass('btn-wrapper--active');         $(this).siblings('.btn-loading').show();         // pass info btn clicked prior modal         // adding hidden input same name btn         $form.append('<input type="hidden" name="'+$clickedbtn.attr('name')+'" value="">');         $form.submit();         return false;     });     $modal.modal('show');     return false; </script> 

if there better way, please share.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -