Learn-to-send-email-via-google-script-html-no-server: Form without email

Created on 19 Jun 2017  路  6Comments  路  Source: dwyl/learn-to-send-email-via-google-script-html-no-server

Thanks so much for this project...it's helping us immensely. One question, though -- is there a way to manipulate the form handler and the script to remove email as a requirement of the form? Basically, we're just asking for a name, telephone number, and message. However, it seems that the email field is a requirement of the coding...and while I'm gaining ground on that, I'm not sure what to remove in order to make the email field a non-requirement. Any help would be appreciated. Thanks!

question

Most helpful comment

I know it sounds ridiculous, but I just figured it out! Sometimes, you just have to take a second look...

Long and short -- and I'll put this here so that others who aren't scripters might want to do the same thing will know how -- once you have your own version of form-submission-handler.js, you also need to remove the following code from it:

_(Near the very top)_
function validEmail(email) { // see:
var re = /^([\w-]+(?:.[\w-]+))@((?:[\w-]+.)\w[\w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i;
return re.test(email);
}

_In the middle:_
if( !validEmail(data.email) ) { // if email is not valid show error
document.getElementById('email-invalid').style.display = 'block';
return false;
} else {

_(and then, the bracket } that matched up with the entire else section so that the if/else section is completely gone, but the things in the else section still happen)_

Thanks again for the comments!

All 6 comments

P.S. I have the form handler working directly from my website, so I can edit that on my end.

@AkiraKaneda you can customise the form fields/validation handler to include/exclude anything you like. 馃憤

I can add things without any problem in my HTML and then just echoing it in my spreadsheet (like the telephone number -- worked like a charm). But when I remove the email component from my HTML and spreadsheet, when I hit "submit," it simply won't process at all. Won't go to my thank you note, won't go to an error screen. It just sits there staring at me. :) So I guess what I'm looking at in the Google script (if I'm looking right) is that the "email" section is necessary. Is that right? What would I remove to get it to work without it? (Like I said, I admit that I am just learning this kind of coding and so I may be missing the obvious.)

@AkiraKaneda You will actually need to have your own version of form-submission-handler.js rather than using the one in the tutorial. This is because that handler is looking to validate the email itself.

I don't know how new you are to javascript, so if you have a play around with it and still need help, just post how far you've managed to get here and I'm sure someone will help 馃槉

I know it sounds ridiculous, but I just figured it out! Sometimes, you just have to take a second look...

Long and short -- and I'll put this here so that others who aren't scripters might want to do the same thing will know how -- once you have your own version of form-submission-handler.js, you also need to remove the following code from it:

_(Near the very top)_
function validEmail(email) { // see:
var re = /^([\w-]+(?:.[\w-]+))@((?:[\w-]+.)\w[\w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i;
return re.test(email);
}

_In the middle:_
if( !validEmail(data.email) ) { // if email is not valid show error
document.getElementById('email-invalid').style.display = 'block';
return false;
} else {

_(and then, the bracket } that matched up with the entire else section so that the if/else section is completely gone, but the things in the else section still happen)_

Thanks again for the comments!

Glad you figured it out with the help :)

FYI, hoping to adapt the tutorial to use data attributes, so this could be modified from the HTML in the future. #94

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tiffting picture tiffting  路  4Comments

mckennapsean picture mckennapsean  路  3Comments

sidbatra picture sidbatra  路  4Comments

onurusluca picture onurusluca  路  4Comments

JintaYadomi picture JintaYadomi  路  3Comments