Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- populating rad chk inputs with posted data


horseatingweeds - 9:02 pm on Aug 12, 2007 (gmt 0)


I'm getting closer. This code works for all of the check elements except for the first one: 'New Puppies'

I get an error for the $pup variable not existing in the form. Anyone see what I'm doing wrong?

<fieldset>
<legend>What do Your Activities Provide?</legend>
<input type='checkbox' name='chkActivities[]' value='New 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>

function popActivities($a)
{
if (isset($_POST['chkActivities']))
{
GLOBAL $pup;
$pup = '';
GLOBAL $adult;
$adult = '';
GLOBAL $trained;
$trained = '';
GLOBAL $stud;
$stud = '';
GLOBAL $rescue;
$rescue = '';
foreach($_POST['chkActivities'] AS $activity)
{
if ($activity == 'New Puppies')
{$pup = "checked='checked'";}
if ($activity == 'Adult Dobermans')
{$adult = "checked='checked'";}
if ($activity == 'Trained Dobermans')
{$trained = "checked='checked'";}
if ($activity == 'Stud Service')
{$stud = "checked='checked'";}
if ($activity == 'Doberman Rescue')
{$rescue = "checked='checked'";}
}
}
echo $a;
}


Thread source:: http://www.webmasterworld.com/php/3419496.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com