Saltar navegación

[Resuelto] Are you Sure? jQuery popup on Form Submit

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

How to add a prompt (pop up) to ask "Are you sure?" on post form submit.

Solution:

Add the jQuery code below:

$('form#the_id').submit(function() {
var c = confirm("Click OK to Submit Note");
return c; //you can just return c because it will be true or false
});

Replace "the_id" with the generated ID for your form.

Relevant Documentation:

https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por nicholasH-6 3 years, 7 months ago.

Asistido por: Christopher Amirian.

Autor
Mensajes
#2495089

Tell us what you are trying to do?
Hi. I'm trying to prompt the user see if they are sure they want to submit the form. I'm using the following code on enlace oculto:

jQuery(document).ready(function($){
$("input[name='form_submit_1']").click(function(event){
event.preventDefault();
if (confirm("Are you sure?")){
$('form#cred_form_9503_1_1').submit();
}
});
});

Please test it. Select any Complaint from the drop down. This form adds a new Complaint Note (Repeatable Group) for a Complaint (Post Type)

But when you click on Submit and then OK from the subsequent pop up I get an error message "Complaints This field is required" when we've already entered a Complaint.

Please help?

Many thanks

Is there any documentation that you are following?
https://toolset.com/forums/topic/are-you-sure-you-want-to-submit/

Is there a similar example that we can see?

What is the link to your site?
enlace oculto

#2495359

Christopher Amirian
Colaborador

Idiomas: Inglés (English )

Hi there,

It is hard to know what is the reason why your JS code is not working and honestly it is outside of our support scope as it is a custom code request.

What I can suggest are the options below:

1- test by adding the code for the Form submit event instead of the click event of the submit button.
2- Test it without the Select2 and see if the method works ok.
3- Use the trigger function and see if it works:
enlace oculto

If the problem persists one thing that I can suggest:

- On the submit event get the current Select 2 selected items in Javascript using the Select 2 library documentation help and save it in an array.
- After the popup and before trying to trigger the submit event, try to re-input the options to Select 2.

Thank you.

#2504617

My issue is resolved now. Thank you! I implemented the following code:

$('form#cred_form_8731_1_1').submit(function() {
var c = confirm("Click OK to Submit Note");
return c; //you can just return c because it will be true or false
});