homepage Welcome to WebmasterWorld Guest from 54.237.98.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
populating rad chk inputs with posted data
horseatingweeds

5+ Year Member



 
Msg#: 3419496 posted 5:11 am on Aug 11, 2007 (gmt 0)

How do you populate input elements other than text inputs with posted data?

 

Dragosh

5+ Year Member



 
Msg#: 3419496 posted 6:48 am on Aug 11, 2007 (gmt 0)

for textarea i do like that :
<textarea><?php echo 'something here'?></textarea>
or you could do that with ajax. how to do that look on w3schools.com

horseatingweeds

5+ Year Member



 
Msg#: 3419496 posted 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;
}

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3419496 posted 5:02 am on Aug 13, 2007 (gmt 0)

I couldn't get the point why you have declared that many global variables. Unless you have a different purpose for them, the following function should do it all:

<?php
function popActivities($a)
{
if (isset($_POST['chkActivities']))
{
foreach($_POST['chkActivities'] AS $activity)
{
if ($activity == 'New Puppies' ¦¦ $activity == 'Adult Dobermans' ¦¦ $activity == 'Trained Dobermans' ¦¦ $activity == 'Stud Service' ¦¦ $activity == 'Doberman Rescue')
{
$chk_status = "checked='checked'";
}
}
}
echo $chk_status;
}
?>

You need to change those "¦¦" to the appropriate vertical ones.

horseatingweeds

5+ Year Member



 
Msg#: 3419496 posted 7:46 am on Aug 13, 2007 (gmt 0)

Hi Habtom,

Won't your function create a checked='checked' for all check elements if even one check element is checked?

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3419496 posted 8:46 am on Aug 13, 2007 (gmt 0)

Won't your function create a checked='checked' for all check elements if even one check element is checked?

No. You are calling the function at all the times. Just to ensure its 'freshness' add the following just after the function:

function popActivities($a)
{
$chk_status = '';

But wait, let me have a second look at it.

[edited by: Habtom at 8:48 am (utc) on Aug. 13, 2007]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved