problem with populating check input with posted data
Posted: Mon Aug 13, 2007 3:06 am
feyd | Please use
Some other code including the include for the form below.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
This function I wrote works fine for all but the FIRST input for some reason. It simple keeps the users inputs in a group of check elements but doesn't work for the first element in the group.
Anyone see the problem or have a better way of doing this?
here is the code:Code: Select all
$pup = '';
$adult = '';
$trained = '';
$stud = '';
$rescue = '';Code: Select all
function popActivities($a)
{
if (isset($_POST['chkActivities']))
{
foreach($_POST['chkActivities'] AS $activity)
{
if ($activity == 'Doberman Puppies')
{
GLOBAL $pup;
$pup = "checked='checked'";
}
if ($activity == 'Adult Dobermans')
{
GLOBAL $adult;
$adult = "checked='checked'";
}
if ($activity == 'Trained Dobermans')
{
GLOBAL $trained;
$trained = "checked='checked'";
}
if ($activity == 'Stud Service')
{
GLOBAL $stud;
$stud = "checked='checked'";
}
if ($activity == 'Doberman Rescue')
{
GLOBAL $rescue;
$rescue = "checked='checked'";
}
}
}
echo $a;
}Code: Select all
<fieldset>
<legend>What do Your Activities Provide?</legend>
<input type='checkbox' name='chkActivities[]' value='Doberman Puppies'
<?php popActivities($pup); ?> /><label>Doberman Puppies</label><br />
<input type='checkbox' name='chkActivities[]' value='Adult Dobermans'
<?php popActivities($adult); ?> /><label>Adult Dobermans</label><br />
<input type='checkbox' name='chkActivities[]' value='Trained Dobermans'
<?php popActivities($trained); ?> /><label>Trained Dobermans</label><br />
<input type='checkbox' name='chkActivities[]' value='Stud Service'
<?php popActivities($stud); ?> /><label>Stud Service</label><br />
<input type='checkbox' name='chkActivities[]' value='Doberman Rescue'
<?php popActivities($rescue); ?> /><label>Doberman Rescue</label><br />
</fieldset>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]