Hello. I would like to immediately say that the popular WP add-ons with forms do not suit me and therefore I am looking for a way to send my own forms from a modal window.
The scheme is approximately the following: On the usual WP pages (page.php), the Fancybox script is connected , which helps with Popups . They are triggered by pushing buttons with jQuery. The page itself has the code of the html-form in a hidden form, it appears only inside the modal window. Next you need to send this form to the post office, but with this it is still difficult.
JS on the form:
$(document).ready(function() { function validatePhone(phone7) { var reg = /[0-9,\s]/i; return reg.test(phone7); } $("#calculation_form").submit(function() { return false; }); var pageurl = window.location.href; $("#url2").val(pageurl); $("#calculation_submit").on("click", function(){ var phoneval = $("#phone7").val(); var phonevalid = validatePhone(phoneval); if(phonevalid == false) { $("#phone7").addClass("error"); } else if(phonevalid == true){ $("#phone7").removeClass("error"); } $('#calculation_form .custom_checkbox').each(function() { if($(this).prop('checked')) { $(this).val('Да'); } }); if(phonevalid == true) { $.ajax({ type: 'POST', url: '/script/phpmailer.php', data: $("#calculation_form").serialize(), success: function(data) { if(data == "true") { $("#calculation_popup").fadeOut("fast", function(){ $(this).before("<div class='success_msg'>Ваша заявка успешно отправлена!<br>С Вами свяжутся в ближайшее время.</div>"); setTimeout("$.fancybox.close()", 3000); }); $('#calculation_form').each(function(){ this.reset(); }); } } }); } }); }); Actually the question is: how to link action = "" from a form from a regular WP page with phpmailer to send a letter? Surely there are pitfalls and you need to dig into functions.php or take into account the feature of CMS.
On many resources ( for example ) they write something similar can be done with admin-post.php , but as I understand it, you need to write the entire form along with the html in the PHP file and on the WP page, in a modal window, somehow call this .php. Also, there are many English-language articles about the contact form without plug-ins ( for example ), but this is still not the case and I do not need one specific page. This form window should be used on many pages.
I will be glad to any useful information. I do not need a fully prepared practical part (although it would not be bad), at least theoretical actions to figure out how it works.