Checkbox in forms

Issues related to forms.
Post Reply
User avatar
crispy68
 
 
Posts: 1036
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Checkbox in forms

Post by crispy68 » Thu Jul 16, 2020 1:14 am

I'm in need of help from the great forum gods.

I've seen a couple of old posts about this and curious if (1) has anyone gotten this to work correctly or (2) has there been an update to make it work and I'm not aware.

Situation:
Have a form with 3 check boxes: Service1, Service2, Service3

When a user checks the boxes, I understand that it turns them to the 'on' position and the value is passed.

In the Form Processor Message that is sent to the owner, I am using the variables: $Service1, $Service2, $Service3

When the form is received, if the checkbox is checked the appropriate value shows. However, the others just show the variable as above.

Is there a way to show only the variable that is checked or either show the ones that are not checked as just 'blanks'?

I would have to think there is a somewhat simple solution to this or using checkboxes would be useless unless you dont mind seeing a bunch of variables in the email. This would look bad if there were numerous checkboxes in your form.

User avatar
BaconFries
 
 
Posts: 4912
Joined: Thu Aug 16, 2007 7:32 pm

Re: Checkbox in forms

Post by BaconFries » Thu Jul 16, 2020 6:20 am

In the checkbox properties what have you used in i.e. name did you include the square brackets as such [] with the text used?
Example:

Code: Select all

<input type="checkbox" name="service[]" value="service 1">
<input type="checkbox" name="service[]" value="service 2">
<input type="checkbox" name="service[]" value="service 3">

User avatar
Pablo
 
Posts: 21461
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Checkbox in forms

Post by Pablo » Thu Jul 16, 2020 6:25 am

In HTML, when a checkbox it not checked the browser will not send the value to the server. So ,the post variable will not even exists on the server side.
In WWB16, there will be an option to workaround this HTML limitation.

lac8383
 
 
Posts: 27
Joined: Sun Mar 24, 2019 6:34 pm

Re: Checkbox in forms

Post by lac8383 » Thu Jul 16, 2020 11:12 pm

Hi Ron (crispy68),

If i have 3 check boxes set in a form, and give them each some text message in the "Value" field
Example:
Name: Checkbox1
Value: You selected Service 1

Name: Checkbox2
Value: You selected Service 2

Name: Checkbox3
Value: You selected Service 3

When checking 1 out of the 3 check boxes and submitting, I receive an email to me in testing with the values: Checkbox1: You selected Service 1

The values for the other check boxes do not appear in the email I send to myself from the form submission.

If I have a that form with a "Success" page with a text box to show the variables ($Checkbox1, $Checkbox2, $Checkbox3), this Success page will show the values for the one checked (You selected Service 1) and the other variables will appear as you stated ($Service2, $Service3) since they were not checked and the value field is not displayed but the email to myself from submission only show the value of what was in $Checkbox1.

Are wanting to send the form submission information to the person's email with the values they checked in the form or are you just displaying this in a Success page after they submit? Is it in an email to them where the variables ($Service1, $Service2, etc.) are displaying since those check boxes weren't checked or just on a Success page?

Regards,
Leo

User avatar
crispy68
 
 
Posts: 1036
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Checkbox in forms

Post by crispy68 » Thu Jul 16, 2020 11:35 pm

Hey Leo,

The variable in the form submitted to the owner is showing in the email.

Here is the checkbox:

Image

name = service1
value = Roof Repair or Service

The other 2 checkboxes are similar. When the box is checked, the value is sent with no issues. However the other 2, I receive the variable names.

Here is the set up I have for the message:

Image

As you can see, in the email being sent it will say:

Type of Service(s) Needed:
Roof Repair or Service
$service2
$service3

The 2 variable names shouldn't show. Based on what Pablo said it kinda makes sense. My thought is there a way to define these variables as blank strings and then if they are not checked, they show a blank and if they are checked then the value is shown? Otherwise, I may have to wait patiently for WB16. :D

User avatar
BaconFries
 
 
Posts: 4912
Joined: Thu Aug 16, 2007 7:32 pm

Re: Checkbox in forms

Post by BaconFries » Fri Jul 17, 2020 12:16 am

Evening crispy68 reading more on this I believe what you are after is something like this
Example:
Name: Checkbox1
Value: You selected Service 1

Name: Checkbox2
Value: You selected Service 2

Name: Checkbox3
Value: You selected Service 3

Correct? if so then as Pablo's reply there is a limitation in HTML that if any of the checkboxes are not checked then there value is not passed.
A little bit of searching I found the following:

Always Get A Checkbox $_POST Value
https://dzone.com/articles/always-get-c ... post-value
It describes how using the original input i.e. checkbox and the using a hidden checkbox and a little javascript then you should get what your after. I haven't tested this but thought I share the link. Note all credit goes to the original author.

GrahamW
 
 
Posts: 291
Joined: Sat Jul 08, 2017 5:02 am

Re: Checkbox in forms

Post by GrahamW » Fri Jul 17, 2020 1:06 am

Hi Ron
have a look at this checkbox demo I did some time ago.
Put a vaild working email in the form and see what it sends you, It sends all the checkbox data that you have ticked and forgets the rest to a text box and lays it out in html format for easy reading

https://shop.grahamscomputers.net/demo/ ... index.html

Graham

User avatar
crispy68
 
 
Posts: 1036
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Checkbox in forms

Post by crispy68 » Fri Jul 17, 2020 1:30 am

@Bacon, thanks... I will take a look at that and see if it might work.

@Graham, checked your demo and yes it did send me only the checked items. The only problem....I've yet to receive my burger!
So, is this an extension you created? I didnt see anything on your website.

GrahamW
 
 
Posts: 291
Joined: Sat Jul 08, 2017 5:02 am

Re: Checkbox in forms

Post by GrahamW » Fri Jul 17, 2020 1:32 am

Hi Ron,

Im trying to make it an extension, I will send you the html code and you can see what you can do with it.

Graham

P.S
im just about to go on a lunch break in 20 mins so I will send it when I get home then

User avatar
crispy68
 
 
Posts: 1036
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Checkbox in forms

Post by crispy68 » Fri Jul 17, 2020 1:35 am

No problem. Take your time. Enjoy your lunch. Make sure my burger is hot. :D

lac8383
 
 
Posts: 27
Joined: Sun Mar 24, 2019 6:34 pm

Re: Checkbox in forms

Post by lac8383 » Fri Jul 17, 2020 4:23 am

Hi Ron

Hopefully, GrahamW has a solution for you.

In the meantime, I found this which has code that may be worth a look for your checkbox issue.

https://www.formget.com/php-checkbox/

Regards,
Leo

Post Reply