Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can use confirm box to submit the form? #192

Open
paladio opened this issue Jul 1, 2022 · 6 comments
Open

How can use confirm box to submit the form? #192

paladio opened this issue Jul 1, 2022 · 6 comments

Comments

@paladio
Copy link

paladio commented Jul 1, 2022

Hi
How can use confirm box to submit the form?

<form action="/action_page.php">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>

  <button type="submit" value="Submit">Submit</button>
</form> 
@despecial
Copy link

Check this JSFiddle from Stephan: http://jsfiddle.net/StephanWagner/cn4921bf/1/

In short: you add an EventListener to the form and on submit trigger the confirmation dialog via jBox.

@paladio
Copy link
Author

paladio commented Jul 1, 2022

Check this JSFiddle from Stephan: http://jsfiddle.net/StephanWagner/cn4921bf/1/

In short: you add an EventListener to the form and on submit trigger the confirmation dialog via jBox.

The code sample sent has a problem and does not work!
I want to widely use conform box for a large number of form elements with different id , I want to be able to use conform box to confirm forms in a more dynamic way.
I don't mean one form element, but many forms in different tables and situation

@despecial
Copy link

The solution is written above: add an Eventlistener to your form(s) and trigger the confirmation box.

The JSFiddle shows the idea of the code. A bit of coding yourself is required.

@paladio
Copy link
Author

paladio commented Jul 1, 2022

The solution is written above: add an Eventlistener to your form(s) and trigger the confirmation box.

The JSFiddle shows the idea of the code. A bit of coding yourself is required.

My scenario is that by giving a specific class "subForm" to each form, it will give a message before submit, and after confirmation, the form will be submitted in the default form.

@StephanWagner
Copy link
Owner

The fiddle doesn't work because it loads the assets from an old CDN library.

As @despecial said, you just have to rewrite the code a little bit to use it with multiple form. That would be one way if you like to use ajax: http://jsfiddle.net/wz9mcf36/

Without ajax, change the button from submit to a normal button and handle the submit manually, like so: http://jsfiddle.net/StephanWagner/f4zeu8pw/

@paladio
Copy link
Author

paladio commented Jul 1, 2022

The fiddle doesn't work because it loads the assets from an old CDN library.

As @despecial said, you just have to rewrite the code a little bit to use it with multiple form. That would be one way if you like to use ajax: http://jsfiddle.net/wz9mcf36/

Without ajax, change the button from submit to a normal button and handle the submit manually, like so: http://jsfiddle.net/StephanWagner/f4zeu8pw/

Thank you dear for your help, I am not very skilled in javascript but what I want is similar to the code below, actually I want to access the target form that is being submitted in the confirm properties in the jbox object So that I can submit it.


$(document).ready(function () {

  $('.any-form').submit(function(ev) {
    ev.preventDefault();
    
    new jBox('Confirm', {
    confirmButton: 'Yes, Confirm',
    cancelButton: 'Cancel',

    confirm: function() {
	ev.target.submit();
    }
  });
  });

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants