Checkbox in forms

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

Checkbox in forms

Post by crispy68 »

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: 5327
Joined: Thu Aug 16, 2007 7:32 pm

Re: Checkbox in forms

Post by BaconFries »

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: 21575
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Checkbox in forms

Post by Pablo »

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 »

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: 2737
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Checkbox in forms

Post by crispy68 »

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: 5327
Joined: Thu Aug 16, 2007 7:32 pm

Re: Checkbox in forms

Post by BaconFries »

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: 240
Joined: Sat Jul 08, 2017 5:02 am

Re: Checkbox in forms

Post by GrahamW »

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: 2737
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Checkbox in forms

Post by crispy68 »

@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: 240
Joined: Sat Jul 08, 2017 5:02 am

Re: Checkbox in forms

Post by GrahamW »

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: 2737
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Checkbox in forms

Post by crispy68 »

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 »

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
lpug
 
 
Posts: 111
Joined: Thu Apr 05, 2018 10:15 am

Checkbox in forms

Post by lpug »

I'm wondering whether there is a workaround this problem in WB17? because its still happening for me.
User avatar
Pablo
 
Posts: 21575
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Checkbox in forms

Post by Pablo »

Did you read the information in the help?
Help -> Contents -> Toolbox -> Checkbox
lpug
 
 
Posts: 111
Joined: Thu Apr 05, 2018 10:15 am

Re: Checkbox in forms

Post by lpug »

Hi Pablo....I did read the help file and my understanding is the following, correct me if I'm wrong.

The checkbox is set to default unchecked.
In the value field I put this off|Test

If the checkbox is checked then the output from the form is correct
If its not checked I still get the output as $example not what i expected as Test because its not checked.....in reality Id like it to be blank

Have I misinterpreted the help file?
Pablo wrote: Fri Jun 10, 2022 5:55 am Did you read the information in the help?
Help -> Contents -> Toolbox -> Checkbox
User avatar
Pablo
 
Posts: 21575
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Checkbox in forms

Post by Pablo »

When you use the workaround (ON | OFF), then
ON will be use when the checkbox is checked.
OFF will be used when the checkbox is unchecked.

Code: Select all

if (!isset($_POST['Checkbox1']))
{
    $_POST['Checkbox1'] = "off";
}
lpug
 
 
Posts: 111
Joined: Thu Apr 05, 2018 10:15 am

Re: Checkbox in forms

Post by lpug »

So my understanding is correct? And yet the output is not changing?

Checkbox is default set to off
Value is set to OFF | Test
So in my example if checkbox is unchecked then output should be outputting Test?

Do I have to copy the script you provided below?

Thanks
Pablo wrote: Fri Jun 10, 2022 8:13 am When you use the workaround (ON | OFF), then
ON will be use when the checkbox is checked.
OFF will be used when the checkbox is unchecked.

Code: Select all

if (!isset($_POST['Checkbox1']))
{
    $_POST['Checkbox1'] = "off";
}
User avatar
Pablo
 
Posts: 21575
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Checkbox in forms

Post by Pablo »

So in my example if checkbox is unchecked then output should be outputting Test?
Correct
Do I have to copy the script you provided below?
No

Without seeing your exact settings it will be difficult to help you.
lpug
 
 
Posts: 111
Joined: Thu Apr 05, 2018 10:15 am

Re: Checkbox in forms

Post by lpug »

Thanks Pablo, I have attached my page, I have stripped everything from it and left one layout grid with checkboxes.
Only the first checkbox has the value as off | Test others I left as default.

https://www.dropbox.com/s/gv0u5oq27x790yv/test.wbs?dl=0

I look forward from hearing from you.
Pablo wrote: Fri Jun 10, 2022 9:06 am
So in my example if checkbox is unchecked then output should be outputting Test?
Correct
Do I have to copy the script you provided below?
No

Without seeing your exact settings it will be difficult to help you.
User avatar
Pablo
 
Posts: 21575
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Checkbox in forms

Post by Pablo »

In your case, it does not work because you are using nested layout grids.
This feature only works if the checkbox is a direct child element of the form.
lpug
 
 
Posts: 111
Joined: Thu Apr 05, 2018 10:15 am

Re: Checkbox in forms

Post by lpug »

Thanks Pablo....I'm assuming it also won't work if I use a flex grid?
User avatar
Pablo
 
Posts: 21575
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Checkbox in forms

Post by Pablo »

It works as long as the checkbox is a direct child element of the layout grid or flexgrid.
Post Reply