Hi there,
I used SendGrid to send out an email notification to both owner and recipient but for some reason I have an Unexpected Token in the end and I cannot figure out where did I make the mistake. It's just there in the end. Please help?
![](https://static.wixstatic.com/media/a27d24_21cbab1da707449faf8d0396b8f682a0~mv2.jpg/v1/fill/w_102,h_33,al_c,q_80,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_21cbab1da707449faf8d0396b8f682a0~mv2.jpg)
});
function sendFormData() {
const subject = `Vous avez reçu un formulaire de ${$w("#input1").value} ${$w("#input2").value}`;
const body = `
\rNom: ${$w("#input1").value}
\rPrénom: ${$w("#input2").value}
\rTéléphone: ${$w("#input3").value}
\rEmail: ${$w("#input4").value}
\rMessage: ${$w("#textBox1").value}`;
const intrests = "\rIntérêts: ";
if ($w("#ArticlesCheckbox").checked) {
intrests = intrests + "\rArticles";
if ($w("#EtaiementCheckbox").checked) {
intrests = intrests + "\rEtaiement";
if ($w("#PasserelleCheckbox").checked) {
intrests = intrests + "\rPasserelle";
if ($w("#PontCheckbox").checked) {
intrests = intrests + "\rPont";
if ($w("#OutilCoffrantCheckbox").checked) {
intrests = intrests + "\rOutil Coffrant";
if ($w("#ButonCheckbox").checked) {
intrests = intrests + "\rButon";
if ($w("#PortiqueCheckbox").checked) {
intrests = intrests + "\rPortique";
if ($w("#MaritimeCheckbox").checked) {
intrests = intrests + "\rMaritime";
if ($w("#DemolitionCheckbox").checked) {
intrests = intrests + "\rDemolition";
if ($w("#SupportGrueCheckbox").checked) {
intrests = intrests + "\rSupport Grue";
if ($w("#DemolitionCheckbox").checked) {
intrests = intrests + "\rDemolition";
if ($w("#AutreCheckbox").checked) {
intrests = intrests + "\rAutre";
const intrests = "\rRecevoir Newsletter: ";
if ($w("#NewsletterCheckbox").checked) {
intrests = intrests + "\rOui";
const intrests = "\rDonnées Confidentielles: ";
if ($w("#ConfidentielleCheckbox").checked) {
intrests = intrests + "\rOui";
}
const recipient = $w("#input4").value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
Indeed, always room to learn - non?
HAHA, very proud indeed. It's funny but I bothered to switch to English so it won't look weird.
Anyway, yes ! this looks like it can work.
I actually went live already with this site, and the client is very happy. Today I also added a different subject line and body for recipient. But there is always room to learn new things and improve.
Good day,
Naama.
Hey Naama,
Glad to see you're still playing with the code.
You can do something like this:
if ($w("#NewsletterCheckbox").checked) { newsletter = newsletter + "Oui"; } else { newsletter = newsletter + "Non"; }
How's that?
Notice how I did it French? Are you proud of me?
Yisrael
Hi again :)
if a box is checked, it'll show in the email - the defined title + Yes.
But what if it is not checked. Is it possible to have it show - the defined title + No?
let newsletter = `\rInterested in Newsletters: `; if ($w("#NewsletterCheckbox").checked) { newsletter = newsletter + "Yes";
Thanks in advance,
Naama.
It was the first semicolon truncating the list; figured it out.
Thanks,
David
I'm also having a problem with the form fields included in the email. I'm using exactly the sendemail code in the article; everything works, except only the first entry passes into the email. There's no error shown in the Editor.
function sendFormData() {
const subject = `Type Your Subject Here ${$w("#demolicemail").value}`;
const body = `Type Here: ${$w("#demolicemail").value}
\rLabelHere2: ${$w("#site").value};
\rLabelHere: ${$w("#mid").value}`;
const recipient = $w("#demolicemail").
This is from the article.
'site' value passes to email; 'mid' doesn't. It's not the form; if I swap 'site' and 'mid' - so mid's first - 'mid' passes. Only \rLabelHere2: shows in the email. \rLabelHere: doesn't.
So it looks like the first body line and the first label line is in the email, nothing after that.
Any suggestions appreciated.
Thanks,
David
HALLELUJAH !!!!
Thanks so much. it looks great, and exactly what I was aiming for :) I really appreciate all the time you've put to help me with this. I learnt a lot from this!
Now I just need to figure out why it goes to spam and how to redirect to a Thank You page when Submit is successful :) I'll try myself first.
A minor fix (not tested though):
let newsletter = `\rRecevoir Newsletter: `; if ($w("#NewsletterCheckbox").checked) { newsletter = newsletter + "Oui"; } let confidentielles = `\rDonnées Confidentielles: `; if ($w("#ConfidentielleCheckbox").checked) { confidentielles = confidentielles + "Oui"; } // <== notice where this bracket is const body = ` \nNom: ${$w("#Nom").value} \nPrénom: ${$w("#Prenom").value} \nTéléphone: ${$w("#Telephone").value} \nEmail: ${$w("#Email").value} \nMessage: ${$w("#Message").value} \n${intrests} \n${newsletter} \n${confidentielles}`;
Notice that I moved the bracket that was the last line of your code in your previous post.
Yep. That did the trick... The email looks good now.
Unfortunately the other 2 checkboxes (under message) are not registering in the email notification.
I tried to imitate the Interests code, but it's not working and now I am also getting errors - "Body unread" and at the bottom "Body undefined". Probably some basic rules I am not familiar with yet...
See how I added the following the same way Interest is written?
\n${newsletter}
\n${confidentielles}
Another thing I trying to do is add a space between the predefined title line and the name that is embedded within "Vous avez reçu un formulaire deTest Test" - need space after "de".
Sorry to bother you so much. One thing for sure, I will have a good solid form-code to use in the future :)
let newsletter = `\rRecevoir Newsletter: `; if ($w("#NewsletterCheckbox").checked) { newsletter = newsletter + "Oui"; } let confidentielles = `\rDonnées Confidentielles: `; if ($w("#ConfidentielleCheckbox").checked) { confidentielles = confidentielles + "Oui"; const body = ` \nNom: ${$w("#Nom").value} \nPrénom: ${$w("#Prenom").value} \nTéléphone: ${$w("#Telephone").value} \nEmail: ${$w("#Email").value} \nMessage: ${$w("#Message").value} \n${intrests} \n${newsletter} \n${confidentielles}`; }
Good morning Naama,
You can space the lines by adding the \n before each line:
const body = ` \nNom: ${$w("#Nom").value} \nPrénom: ${$w("#Prenom").value} \nTéléphone: ${$w("#Telephone").value} \nEmail: ${$w("#Email").value} \nMessage: ${$w("#Message").value} \n${intrests}`;
Glad I was able to help.
Yisrael
Amazing!!! Thank you very much. I learn a lot from you.
I tried your code and it worked indeed :)
BTW - the before and after didn't really show the difference because they were not in the same proportions, here it is again with equal proportions...
Unfortunately it really doesn't look good.
If you would have the extra time tomorrow to figure this out, and bring it back to the original format it would be great. Otherwise, I will keep trying to find the answers myself :)
Here's how to handle the commas:
let comma = ""; // no comma needed for first option in list let intrests = `\rIntérêts: `; if ($w("#ArticlesCheckbox").checked) { intrests = intrests + "Articles"; comma = ", "; } if ($w("#EtaiementCheckbox").checked) { intrests = intrests + comma + "Etaiement"; comma = ", "; } if ($w("#PasserelleCheckbox").checked) { intrests = intrests + comma + "Passerelle"; comma = ", "; } if ($w("#PontCheckbox").checked) { intrests = intrests + comma + "Pont"; comma = ", "; } if ($w("#OutilCoffrantCheckbox").checked) { intrests = intrests + comma + "Outil Coffrant"; comma = ", "; } if ($w("#ButonCheckbox").checked) { intrests = intrests + comma + "Buton"; comma = ", "; } if ($w("#PortiqueCheckbox").checked) { intrests = intrests + comma + "Portique"; } if ($w("#MaritimeCheckbox").checked) { intrests = intrests + comma + "Maritime"; comma = ", "; } if ($w("#DemolitionCheckbox").checked) { intrests = intrests + comma + "Demolition"; comma = ", "; } if ($w("#SupportGrueCheckbox").checked) { intrests = intrests + comma + "Support Grue"; comma = ", "; } if ($w("#DemolitionCheckbox").checked) { intrests = intrests + comma + "Demolition"; comma = ", "; } if ($w("#AutreCheckbox").checked) { intrests = intrests + comma + "Autre"; } if(comma !== ", ") intrests = "";
I use a variable called comma, which as you can see, I start it out as blank. It will only "become" a comma once an option is included in the list. Then every time after that a comma will be put between options.
A nice side-effect from this is if after checking all of the checkboxes none has been checked, we can just clear the intrests string to blank and it won't appear in the body of the email.
There might be better ways to do this, but my brain is tired. This works and at least gives you a presentable email.
Note: I did not make these changes to your site.
Don't regret it all! In fact, this has proven to be pretty interesting. I've been spending my time reading up on template literals since I'm still not sure about some usage cases.
I don't believe that the font is smaller - it's the same size as in the previous example. The difference is that the line with the checkbox data is in a larger font. And I have no idea why that is. It has something to do with template literals, which as I said are confusing me. It seems that the use of a template literal affects the formatting in much more sinister ways than I originally imagined.
Another strange thing is that in the emails that I'm receiving I get the body of the email in a fairly nice and large font.
< The comma issue addressed in the next post. >
I bet you already regret getting into this :) hahaha... I wish I understood it all better...
First, I am totally ok with the commas on Interests, can you show me an example of how to do this and I'll apply to everything else?
Second, the new design of the email is, well... not quite right. See before and after... The new design is display the first part in a very small font.
BEFORE:
AFTER:
OK, the email is now formatted, and the checkbox data is once again displayed in the body of the email.
I just can't figure out how to get the checkbox data to appear on separate lines. Something with the template literal I don't understand. You could always "cheat" and just separate the checkbox data with commas. For example:
Intérêts: Articles, Etaiement, Passerelle
I've closed the editor so you can go back in without me being in the way.
As I was saying.. the checkbox data IS saving in the database... as always. It is just not showing- up on the email notification, and it should...
I logged out from the editor, which by the way the code is now full of errors... :(
Looking at your original code, it seems that the booleans weren't added to the email body. Not sure if I messed that up, or it got messed up when you were making some changes. As soon as I have access to your site, I'll fix it up.
I'm getting checkbox data saved in the database of my cloned site. Very strange that it's not being save correctly on yours.
Please close your editor. I'll fix the "pretty email" issue (I hope), and then I'll take a look at the checkboxes on your site.
As I mentioned long-long ago in the beginning of this thread - the submitted data was always saving properly in the Database, including marked Boolean checkboxes. The problem is that it isn't registering in the notification emails.
With all your efforts, and regardless of how pretty the email should be, unfortunately I still don't see the checked Booleans registered in the notification email.... Did you get the checked booleans showing on your test notification email?
Got it! Wasn't too bad. My fault!
In my zeal to uncover the problem, I got rid of the critical ` marks. These enclose a template literal, and therefore I need to restore parts of your code - that is, I need to change ' to `.
Close the editor so I can go and fix things without causing a conflict with your actions.