Forum Moderators: coopster

Message Too Old, No Replies

checkbox prob?

         

fukchai2000

11:26 am on Oct 21, 2004 (gmt 0)

10+ Year Member



this is part of the code

<FORM ACTION="test.php" METHOD=POST>
<P> Please tell us what you thought of this Web site. Select the checkboxes which you agree with: </P>
<UL>
<LI><INPUT TYPE=chECKBOX NAME="opinion" VALUE="understandable">
The text was understandable.
<LI><INPUT TYPE=chECKBOX NAME="opinion" VALUE="navigable">
I found it easy to find my way through the Web site.
<LI><INPUT TYPE=chECKBOX NAME="opinion" VALUE="stylish">
I was impressed by the style and presentation.
</UL>
<P> <INPUT TYPE="HIDDEN" NAME="pages" VALUE="brochure">
Please add any other comments:
<TEXTAREA NAME="feedback" ROWS=5 COLS=40>
I think your brochure is:
</TEXTAREA>
</P>
<P> <INPUT TYPE=SUBMIT VALUE="Send comments">
<INPUT TYPE=RESET VALUE="Clear form"> </P>
</FORM>

i try to print out all the checkbox value....
i check all the boxes and click the submit....

and my test.php is only:

print $_POST['opinion'];

but it prints out only "stylish" (the last checkbox value)

can somebody help me with this....coz i can't print the whole checkbox value even i've checked all the boxes?

Birdman

12:10 pm on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!

In the HTML form, name your checkbox inputs as an array like so:

<INPUT TYPE=chECKBOX NAME="opinion[]" VALUE="understandable">

Do that with all of them, then in your script you can loop the array to get all the values:

foreach ($_POST['opinion'] as $val){
print $_POST['opinion'][$val] . '<br />';
}

Regards,
Birdman

fukchai2000

12:21 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



thanks dude...that really help....never use array as a name b4...

thanks...

coopster

12:23 pm on Oct 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



This PHP page in the manual should help. It has some other techniques as well...

PHP and HTML [php.net]