Check Box PHP

They have: 1 posts

Joined: Nov 2009

Hi all first post to the forum.
I have been developing a form that has many radio buttons and have managed to output this to email using Php. Now I thought I would be clever and use check boxes for a question on credit card types.The user may have more than one card. I have spend three weekends now trying to get some Php code to make it output to the email. But this seems to be a different ball game. Although I have managed to get the radio buttons working I can not program in Php. I thought I got close on a number of occasions with the check box and had an email that displayed "Array" instead of the checked box values. Now I an quite confused. If any one could help with some Php for this I would be most grateful. This is my form without the submit side of it.

<label><input type="checkbox" name="Credit[]" value="Amex" />
                Amex</label>
<br />
<label><input type="checkbox" name="Credit[]" value="Diners"/>
Diners</label>
<br />
<label><input type="checkbox" name="Credit[]" value="Debit Card"/ >
Debit Card </label>
<br />
<label><input type="checkbox" name="Credit[]" value="Mastercard" />
Mastercard</label>
<br />
<label><input type="checkbox" name="Credit[]" value="None" />
None</label>
<br />
<label><input type="checkbox" name="Credit[]" value="Visa" />
Visa</label>

Many Thanks
Weka1

They have: 5 posts

Joined: Mar 2010

My best guess is you're using the same name for every checkbox..
just change the names of the checkboxes and you'll be fine.
You'll receive it in your email probably like (for example) visa=checked

bigmax's picture

They have: 1 posts

Joined: Mar 2010

Alternatively to what avido wrote, you might also simply expand the checkbox array with a loop (say foreach $chk[] as $value) and get the checked values from there. Don't forget to name your checkbox accordingly though, using the square brackets in your submit form.

Affordable web design and development. http://www.egofirm.com

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

avido wrote:
My best guess is you're using the same name for every checkbox

For using checkboxes with PHP, this IS what you need to do so that when it goes back to PHP, gets converted over to array. (the suare brackets are required too).

I starts putting together a sample form to demonstrate it, well it balloned into a full "contact us" tutorial/sample. See it here: http://www.webmaster-forums.net/web-programming-and-application-developm...

-Greg

They have: 33 posts

Joined: Apr 2010

if you find arrays difficult to handle, then you should not use the names as you used in your script. Instead try the following:

<label><input type="checkbox" name="amex" value="yes" />
                Amex</label>
<br />
<label><input type="checkbox" name="diners" value="yes"/>
Diners</label>
<br />
<label><input type="checkbox" name="debit_card" value="yes" />
Debit Card </label>
<br />
<label><input type="checkbox" name="mastercard" value="yes" />
Mastercard</label>
<br />
<label><input type="checkbox" name="none" value="yes" />
None</label>
<br />
<label><input type="checkbox" name="visa" value="yes" />
Visa</label>

Although in this case you will need to do it manually. If you can post here more details and the whole script, we will be in a better position to help you solve this problem.

He has: 53 posts

Joined: Jun 2010

Hi, that's fine and i suggest you jut "visit w3schools.com", for more help.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.