Jump to content

Drop down lists won't retain previous data


This topic is 2229 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a survey page that uses FMFind to find an existing record which is then updated by new survey data for comparison.

http://www.acwa.asn.au/Pages/djppostcourseevaluation.php?recid=20989

The drop-down lists don't display previous data.

For example:

// variables extracted from database by FMFind
$djpenjoy =   $findnewevaluationData['djpenjoy'][0];

//isset code
if (isset($_REQUEST['djpenjoy'])) $djpenjoy = $_REQUEST['djpenjoy'];

 

//select code<select name="djpenjoy" size="1">
<?php
$enjoyoptions = array('' => '', 'Not at all' => 'Not at all', 'Somewhat' => 'Somewhat', 'Almost all' => 'Almost all', 'Very much' => 'Very much');
$selected = '';
if (isset($_REQUEST['djpenjoy']) && in_array($_REQUEST['djpenjoy'], $enjoyoptions)) {
// If someone has selected an option (i.e. previously submitted the form) then change the default value
$selected = $_REQUEST['djpenjoy']; 
}
// Loop through each option in $opts adding it as an option to the select. If the key from the array matches the selected (default) value then mark the item as selected
foreach ($enjoyoptions as $k => $v) { 
echo '<option value="' . htmlentities($k, ENT_QUOTES) . '"';
if ($k == $selected) {
echo ' selected="selected"';
}
echo '>' . htmlentities($v, ENT_QUOTES) . '</option>'; 
}
?>
 </select>

What am I missing?

Link to comment
Share on other sites

This will work if there is a Request for djpenjoy set in the loading URL. But if $djpenjoy is set, then it won't, as the array check to $enjoyoptions requires a Request...

Try changing this line to:

if (isset($djpenjoy) && in_array($djpenjoy, $enjoyoptions)) {

 

Link to comment
Share on other sites

Assuming the $findnewevaluationData['djpenjoy'][0]; returns a value, then there needs to a test around whether $dpenjoy has already been set... Try:


// variables extracted from database by FMFind
$djpenjoy = $findnewevaluationData['djpenjoy'][0];

//isset code
if ( $dpenjoy == "") {
	if (isset($_REQUEST['djpenjoy'])) $djpenjoy = $_REQUEST['djpenjoy'];
}

 

Link to comment
Share on other sites

This topic is 2229 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.