Good day! I need your help, gentlemen.

Background:

The site has a form, you need to make it so that:

  1. The form sent data to Google form (beautifully forming in the tables).
  2. In the form there is a field "e-mail", after sending, the user should be sent a letter in the mail informing about the registration.
  3. After registering, the user must somehow be informed that the form works and does not simply refresh the page after clicking the "send" button.

With the first paragraph, I figured out, on the Internet a lot of information about this. The form sends data to the tables.

<form class="contact_form form" action="https://docs.google.com/forms/d/e/bl-bla-bla/formResponse" method="post"> <ul> <li><input placeholder="Π’Π΅ΠΌΠ°0" type="text" name="entry.82222974"></li> <li><input type="text" placeholder="E-mail" name="mail" name="entry.1824090412"></li> <li><input type="text" placeholder="Π’Π΅ΠΌΠ°1" name="entry.1638850810"></li> <li><input type="text" placeholder="Π’Π΅ΠΌΠ°2" name="entry.856932552"></li> <li><input type="text" placeholder="Π’Π΅ΠΌΠ°3" name="entry.1016239961"></li> <li><input type="text" placeholder="Π’Π΅ΠΌΠ°4" name="entry.1906109374"></li> <li><button class="submit" type="submit"/>ΠžΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ</button></li> </ul> <p class="msgs"></p> </form> 

I figured out the second item, too. I used this manual .

Separately, everything works well, but as soon as I put everything together, sending into Google form stops working.

I understand that it does not work because of this script, which is responsible for sending the letter and displaying the message under the form Thank you for registration! because It works through AJAX and does not reload the page, and sending data to the Google table is done by reloading the page.

 $(document).ready(function () { $("form").submit(function () { // ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ ID Ρ„ΠΎΡ€ΠΌΡ‹ var formID = $(this).attr('id'); // Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Ρ€Π΅ΡˆΡ‘Ρ‚ΠΊΠΈ ΠΊ ΠΈΠΌΠ΅Π½ΠΈ ID var formNm = $('#' + formID); var message = $(formNm).find(".msgs"); // Π˜Ρ‰Π΅Ρ класс .msgs Π² Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Ρ„ΠΎΡ€ΠΌΠ΅ ΠΈ записываСм Π² ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ var formTitle = $(formNm).find(".formTitle"); // Π˜Ρ‰Π΅Ρ класс .formtitle Π² Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Ρ„ΠΎΡ€ΠΌΠ΅ ΠΈ записываСм Π² ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ $.ajax({ type: "POST", url: 'sendmail/mail.php', data: formNm.serialize(), success: function (data) { // Π’Ρ‹Π²ΠΎΠ΄ сообщСния ΠΎΠ± ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠΉ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠ΅ message.html(data); formTitle.css("display","none"); setTimeout(function(){ //$(formNm).css("display","block"); $('.formTitle').css("display","block"); $('.msgs').html(''); $('input').not(':input[type=submit], :input[type=hidden]').val(''); }, 3000); }, error: function (jqXHR, text, error) { // Π’Ρ‹Π²ΠΎΠ΄ сообщСния ΠΎΠ± ошибкС ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠΈ message.html(error); formTitle.css("display","none"); // $(formNm).css("display","none"); setTimeout(function(){ //$(formNm).css("display","block"); $('.formTitle').css("display","block"); $('.msgs').html(''); $('input').not(':input[type=submit], :input[type=hidden]').val(''); }, 3000); } }); return false; }); }); 

Now the most important question is how and what needs to be changed in this script, so that the letter is sent, the text is output and the data is recorded in a Google form? Can it be replaced by sending a letter and outputting text to something else?

I would be very grateful for your reply, as I have been racking my brains for half a day already.

  • I did something similar, but the messages were sent by the goole script in the document. - ilyaplot

1 answer 1

 return false; 

change to

 return true; 

submit is called before the form is submitted, and if false is returned, the form is not submitted and you will remain on the same page (data will not be sent to Google Docs, respectively).