Email on Form Submission

Hello,

I have created a form.
After submitting the form should be sent me an email.
That works too.

However, everything is always displayed to me.
How do I have to change the entry that the entry of the checkbox is displayed to me only if the checkbox was selected?

I hope I could explain it understandably, since my English is bad.

Greetings Ronny

This is what my event handler looks like:

import {sendEmail} from 'backend/email';

$w.onReady(function () {
  $w("#dataset1").onAfterSave(sendFormData);
});

function sendFormData() {
  const subject = `Neue Anfrage von ${$w("#input1").value}`;
  const body = `Name: ${$w("#input1").value}
    \rName: ${$w("#input1").value}
    \rTelefonnummer: ${$w("#input2").value}
    \reMail: ${$w("#input3").value}
    \reMail2: ${$w("#input4").value}
    \rOrt: ${$w("#input5").value}
    \rVeranstaltungsart: ${$w("#dropdown1").value}
    \rVeranstaltungsdatum: ${$w("#datePicker1").value}
    \rGästezahl: ${$w("#dropdown2").value}
    \rPersonalisiertes Gobo: ${$w("#checkbox1").value}
    \rAmbiente-Beleuchtung: ${$w("#checkbox2").value}
    \r2-Zonen-Beschallung: ${$w("#checkbox3").value}
    \rEröffnungstanz-Mix: ${$w("#checkbox4").value}
    \rMitteilung: ${$w("#textBox1").value}
    \rDatenschutz gelesen: ${$w("#checkbox5").value}`;
     
  sendEmail(subject, body)
    .then(response => console.log(response)); 
}

Hi,
Can you please send us a screenshot of the page? I’m not sure that I understand the use case.
Do you wish to send an Email Notification only if a checkbox is selected?
Please clarify what you would like to achieve.

Thanks,
Tal.

Hi,

many thanks for your response.
The notification should always be made when a request has been sent.
That works too.

In the mail, however, the checkboxes are always displayed, even if they have not been selected.
Checkboxes that were not selected but should not be displayed.

Greetings Ronny

Unfortunately, I still do not get on.

???

Does not anyone have a solution to the problem?

Hi,
I’m truly sorry for the delay. You should check the checkboxes values before concatenating them to the body string. it should look something similar to the following:

let body = `Name: ${$w("#input1").value}     
 \rName: ${$w("#input1").value}     
 \rTelefonnummer: ${$w("#input2").value}     
 \reMail: ${$w("#input3").value}     
 \reMail2: ${$w("#input4").value}     
 \rOrt: ${$w("#input5").value}     
 \rVeranstaltungsart: ${$w("#dropdown1").value}     
 \rVeranstaltungsdatum: ${$w("#datePicker1").value}     
 \rGästezahl: ${$w("#dropdown2").value}       
 \rMitteilung: ${$w("#textBox1").value}     
 \rDatenschutz gelesen: ${$w("#checkbox5").value}`;
 
 
 if ($w("#checkbox1").value){
     body+= `\rPersonalisiertes Gobo: ${$w("#checkbox1").value}`;
 }

 
 if ($w("#checkbox2").value){
     body+= `\rAmbiente-Beleuchtung: ${$w("#checkbox2").value}`;
 }

if ($w("#checkbox3").value){
     body+= `\r2-Zonen-Beschallung: ${$w("#checkbox3").value}`;
 }

if($w("#checkbox3").value){
    body += `\rEröffnungstanz-Mix: ${$w("#checkbox4").value}`;
}

I hope it’s clear.

Have a good day,
Tal.

Hello

thank you for your message.
I will try it that way.

wish you a nice day
Ronny

This unfortunately gives me error messages.

Firstly, the body variable should be declared as let instead of const . Click here to learn more about the difference. Moreover, you need to make sure that the variable ends with " ; " and that the string ends with backtick ( ` ) before using the if statement.
I recommend copying the code that I wrote above and make the necessary changes.

Tal.

Okay…
Thank you for your answer.
This is unfortunately too complicated for me, because I have no programming knowledge.
Unfortunately, I can not speak English, so I can not learn it with the help of the link.
Then I can not use the function.
Many Thanks
Greetings Ronald