May 16, 20169 yr 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?
May 17, 20169 yr 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)) {
May 19, 20169 yr Author It's now showing selected data when the page is returned to during a submission process but it doesn't display existing data from the database from a previous submission.
May 19, 20169 yr 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']; }
Create an account or sign in to comment