Search…

X3 Photo Gallery Support Forums

Search…
 
User avatar
Dane
Experienced
Topic Author
Posts: 88
Joined: 04 Dec 2020, 15:05

Multiple choices checkboxes in contactform

23 Dec 2020, 14:16

Hi,

i have a problem with the checkbox for multiple choises. I use this code:
<div>
<strong>Art der Hochzeit</strong><br>

<input type="checkbox" name="Art der Hochzeit" value="Standesamtliche Trauung" id="check1">
<label for="check1">Standesamtliche Trauung</label>

<input type="checkbox" name="Art der Hochzeit" value="Kirchliche Trauung" id="check2">
<label for="check2">Kirchliche Trauung</label>

<input type="checkbox" name="Art der Hochzeit" value="Freie Trauung" id="check3">
<label for="check3">Freie Trauung</label>
</div>
And it looks so, and this is i want:
2020-12-23 20_07_13-Window.png
2020-12-23 20_07_13-Window.png (3.18 KiB) Viewed 624 times
But when i send the form, the e-mail has only information about one checkbox. But in the form i marked two checkboxes. 
2020-12-23 20_07_32-Window.png
2020-12-23 20_07_32-Window.png (6.12 KiB) Viewed 624 times
The Name in the code is the same, but diffrent values. I think that should be correkt when i google about HTML checkboxes. 

Normally it should look like this:
Art der Hochzeit
Standesamtliche Trauung, Freie Trauung
Where is my mistake?

Thanks!
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12765
Joined: 30 Sep 2006, 03:37

Re: Multiple choices checkboxes in contactform

24 Dec 2020, 00:11

You need assign a unique NAME attribute for all your unique form items. In your case, you have name="Art der Hochzeit" for all three checkboxes. The name must be used to identify what the value of the property is for.
Code
<input type="checkbox" name="UNIQUE NAME HERE PLEASE" value="..." id="...">
 
User avatar
Dane
Experienced
Topic Author
Posts: 88
Joined: 04 Dec 2020, 15:05

Re: Multiple choices checkboxes in contactform

24 Dec 2020, 02:35

Ok, thank you. I have also tried this before, with the following code:
Code
<div>
<strong>Art der Hochzeit</strong><br>

<input type="checkbox" name="Art der Hochzeit 1" value="Standesamtliche Trauung" id="check1">
<label for="check1">Standesamtliche Trauung</label>

<input type="checkbox" name="Art der Hochzeit 2" value="Kirchliche Trauung" id="check2">
<label for="check2">Kirchliche Trauung</label>

<input type="checkbox" name="Art der Hochzeit 3" value="Freie Trauung" id="check3">
<label for="check3">Freie Trauung</label>
</div>
And when I check Check1 and Check 3 and send the form, it looks like this in the mail:
Art der Hochzeit 1
Standesamtliche Trauung

Art der Hochzeit 3
Freie Trauung
But it should look like this:
Art der Hochzeit
Standesamtliche Trauung, Freie Trauung
Because is yes a question with multiple answers, so that should be listed but also in the mail under a (the only one) question and then the multiple answers? In my case each selection has its own heading. I think that should not be in a question with multiple answers?

Example:
What are your hobbies?
X Swimming
O Cycling
X Shopping
In my case, tha mail looks like this with diffrent "names":
What are your hobbies? 1
Swimming

What are your hobbies? 2
Shopping
But it should looks like this in the mail:
What are your hobbies?
Swimming, Shopping
Is that even possible? I thought the "name" combines the answers under one question.
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12765
Joined: 30 Sep 2006, 03:37

Re: Multiple choices checkboxes in contactform

24 Dec 2020, 04:22

So if it's a SINGLE item with MULTIPLE options, you should be using RADIO BOXES not check boxes. Radio boxes are for a single item, where user can check ONE item of all options. As for checkboxes, they are all independent. One checkbox is either ON (selected) or OFF (de-selected) and it does not and cannot related to other check boxes. That is what radio boxes are for, selecting the value for a single question.

As for the X3 FORM / EMAIL system, it's automatic and will simply reflect the NAMED forms and their VALUES. You could customize it, but that requires some basic re-coding in PHP. As for selecting "multiple items", this is not something that checkboxes is made for ... You could use checkboxes, but checkboxes are all independent so the output would be like this, with independent items:

Ice cream
Yes

Chocolate
Yes

Cake
No

The only TRUE way to achieve "multi-select" for a single property, is to use <select> field with multiple attribute. Find an example with code in the link below:
https://html.com/attributes/select-multiple/
Code
<select name="NAMEHERE" multiple size="6">
  <option value="American">American flamingo</option>
  <option value="Andean">Andean flamingo</option>
  <option value="Chilean">Chilean flamingo</option>
  <option value="Greater">Greater flamingo</option>
  <option value="James's">James's flamingo</option>
  <option value="Lesser">Lesser flamingo</option>
</select>
 
User avatar
Dane
Experienced
Topic Author
Posts: 88
Joined: 04 Dec 2020, 15:05

Re: Multiple choices checkboxes in contactform

24 Dec 2020, 04:41

Hi Karl,

thank you for the explanation. Now i unterstand it. 

I have another question about the name, who is also in the title of the e-mail. In my e-mail, the part with the name looks ike this:
From: %name%
Because i have two fields for two names. It is supposed to be a form for bridal couples where both have to give their names. So my code looks like this:
Code
<!-- All form elements must contain NAME attributes-->
<div>
<input type="text" name="Vor- und Nachname Braut" placeholder="Vor- und Nachname Braut" required>
</div>

<div>
<input type="text" name="Vor- und Nachname Bräutigam" placeholder="Vor- und Nachname Bräutigam" required>
</div>
This will probably be the problem, why in the mail no name is specified in the title or sender, because there for this the variable %name% is used. What can I do here? 
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12765
Joined: 30 Sep 2006, 03:37

Re: Multiple choices checkboxes in contactform

24 Dec 2020, 07:39

Is there no NAME input field where the visitor inputs their name? How do you know who's sending the form if there is no name?

Now, the point of %name% is a variable that would get the name from <input type="text" name="name" placeholder="Name" required>. In your case, you have <input type="text" name="Vor- und Nachname Bräutigam" placeholder="Vor- und Nachname Bräutigam" required>, but why are you creating so complex name values? The user does not see this field, and it's like a unique ID for the specific input item. Why not change it to <input type="text" name="braut" placeholder="Vor- und Nachname Braut" required> where name is a proper ID? Surely you can recognize that property "brait" in your incoming emails forms. This is how X3 automatically deals with fields you add ... It uses the NAME and the VALUE of that attribute, and then you can use %braut% as a variable in the contact form template ... However, that is not necessary as it will automatically add them for all your input fields. However, the %name% var is special because it's considered part of all contact forms ... Options:
  1. Ignore it. It doesn't hurt that the email that only you read contains a line %name%. It's just that you don't have a field with "name".
  2. Rename one of your input fields to name="name". Only you will see this in the email. Besides, all emails to you need to be from someone (a name).
  3. Create your own TEMPLATE for your custom contact form. Then you can remove the %name% variable, but what's the point if it has no functional purpose, and it will be a technical challenge to create your own template?
 
User avatar
Dane
Experienced
Topic Author
Posts: 88
Joined: 04 Dec 2020, 15:05

Re: Multiple choices checkboxes in contactform

27 Dec 2020, 13:25

Thank you for the explanation. This was really helpful to understand it.