You are here: Re: Using Post with Multiple Checkboxes ? « All PHP « IT news, forums, messages
Re: Using Post with Multiple Checkboxes ?

Posted by Rik on 03/05/07 11:18

Philb <nothanks@spamfree.net> wrote:

> Can someone lend a hand with this please, i've been on it for ages and=
=

> still can't figure out where I'm going wrong.
>
> I have a simple form with 4 checkboxes, I want to post the info from t=
he =

> checkboxes and have it displayed on the next page.
>
> Html Form to let a person pick their favourite t-shirt color....
>
> e.g.
> Select your favourite T-shirt color.
> Red
> White
> Blue
> Yellow
>
>
>
> <form method=3D"post" action=3D"colorsubmit.php">
> <p>Select your favorite T-shirt color.</p>
> <input type=3D"checkbox" name=3D"tcolor[red]" value=3D"Red">Red<br />
> <input type=3D"checkbox" name=3D"tcolor[white]" value=3D"White">White<=
br />
> <input type=3D"checkbox" name=3D"tcolor[blue]" value=3D"Blue">Blue<br =
/>
> <input type=3D"checkbox" name=3D"tcolor[yellow]" value=3D"Yellow">Yell=
ow<br />
> <input type=3D"submit" value=3D"submit">
> </form>
>
>
>
> The PHP on the next page looks like this 'colorsubmit.php'
>
> <?php
> $tcolor[red]=3D$_POST['tcolor[red]'];
> $tcolor[white]=3D$_POST['$tcolor[white]'];
> $tcolor[blue]=3D$_POST['$tcolor[blue]'];
> $tcolor[yellow]=3D$_POST['$tcolor[yellow]'];
> ?>
> You chose
> <?php
> echo $tcolor[red], $tcolor[white], $tcolor[blue], $tcolor[yellow]
> ?>

Indeed, you heard somewhere that it's a nice to use the [] in =

select/checkbox names, but that's because they will autmatically generat=
e =

an array for you. Try print_r($_POST) to see what you get.

Also, drop the $ in the second part of the statements, they aren't =

variables but strings, and in the first part, quote the strings. Hmm, th=
at =

sounds somewhat hazy. Illustration:

$tcolor['red']=3D$_POST['tcolor[red]'];

Would be correct, but php has already provided something for you:

$tcolor['red']=3D$_POST['tcolor']['red'];

Or actually, in this case, everything can be replaced by:

$tcolor =3D $_POST['tcolor'];
echo 'You chose: '.implode(', ',$tcolor);

-- =

Rik Wasmus
Posted on Usenet: any site claiming this as original content or me as an=
=

contributing member is wrong.
Ask Smart Questions: http://tinyurl.com/anel

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация