|
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
Navigation:
[Reply to this message]
|