Check Box PHP

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

arbaba
Posts: 1
Joined: Sat Feb 05, 2011 10:09 am UTC

Check Box PHP

Postby arbaba » Sat Feb 05, 2011 10:12 am UTC

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>



_______________________________

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: Check Box PHP

Postby Emu* » Sat Feb 05, 2011 1:49 pm UTC

instead of

$_post['credit']

try

implode($_post['credit'], ', ')

which should turn the array into a string containing the list. Alternatively check out foreach.
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

User avatar
Xanthir
My HERO!!!
Posts: 5426
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Check Box PHP

Postby Xanthir » Sat Feb 05, 2011 6:18 pm UTC

So, PHP treats inputs ending in [] specially - it collects them into an array automatically for you.

So, given code like you have above, the variable $_POST['Credit'] is actually an array of values. Just treat it like any other array. You can loop through it, implode it, sort it, whatever.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests