Reply to Re: Array Issue - Correspoing checkbox and textfield values to behave

Your name:

Reply:


Posted by Rik on 07/18/07 01:42

On Wed, 18 Jul 2007 03:00:27 +0200, newbie <alen198@gmail.com> wrote:

> Hello All,
>
> I'm trying to figure out this array problem I have. I don't know if
> I'm doing this correctly. Anyone want to take a look.
>
> ---------------------
> Current Situation.
> ---------------------
> I have a form with checkboxes and corresponding textfields for each
> checkbox. Here is the HTML
>
> <input type=3D"checkbox" name=3D"shows[]" value=3D"Morning">Morning</
> option># of People<input type=3D"text" name=3D"people[]" value=3D"" />=

> <input type=3D"checkbox" name=3D"shows[]" value=3D"Lunch">Lunch</optio=
n># of
> People<input type=3D"text" name=3D"people[]" value=3D"" />
> <input type=3D"checkbox" name=3D"shows[]" value=3D"Evening">Evening</
> option># of People<input type=3D"text" name=3D"people[]" value=3D"" />=


So, in short, the problem is unchecked checkboxes don't get send, which =
is =

default behaviour);

Solution:

Checkbox name: "shows[]"
Text names: "people[<show_value>]" (so: people[Morning], people[Lunch] =
=

etc.)

(Oh yeah: and get rid of your unopened </options>'s... validate your HTM=
L =

:-) )

Receiving end:
foreach($_POST['shows'] as $show){
$num =3D isset($_POST['people'][$show]) ? intval($_POST['people'][$sho=
w]) =

: 0;
echo "$num people for $show show";
}

However, is there a special need to have both a checkbox AND a textfield=
? =

Surely this is double work for your users, and they can just leave a tex=
t =

field blank if they don't choose that option?
-- =

Rik Wasmus

[Back to original 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

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