PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
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]
function popActivities($a)
{
if (isset($_POST['chkActivities']))
{
foreach($_POST['chkActivities'] AS $activity)
{
switch ($activity)
{
case 'Doberman Puppies':
GLOBAL $pup;
$pup = "checked='checked'";
break;
case 'Adult Dobermans':
GLOBAL $adult;
$adult = "checked='checked'";
break;
case 'Trained Dobermans':
GLOBAL $trained;
$trained = "checked='checked'";
break;
case 'Stud Service':
GLOBAL $stud;
$stud = "checked='checked'";
break;
case 'Doberman Rescue':
GLOBAL $rescue;
$rescue = "checked='checked'";
break;
}
}
}
echo $a;
}
Not entirely sure why the first form input element doesn't validate.
If you remove the the first input element (Doberman Puppies) you will notice that "Adult Dobermans" will not be checked. It seems as though the ver first array value is being ignored.
I played about with it and i know its not ideal but the following works:
Hi there horseatingweeds,
If you go through the flow of the program one by one, you will figure out the problem that lies....well if you study your code you'll see that after you've submitted the form the first call to "popActivities($pup)" sets the variables
$pup;
$adult;
$trained;
$stud;
$rescue;
DID U GET THE PROB NOW?? NOO!
Well then, back to first call to the popActivities($pup) after the form submission, here $pup is set to nothing...it is after this first call your global variables are set(all of them in the first call).....ie for those checkboxes that are set the value will be set to "checked='checked' " for corresponding variables, hence on your consecutive calls to popActivities() your variables are set so it prints the desired checked effect....
ummm i don;t think i made things clearer so i'll give the solution then