Hello,
I'm trying to retrieve and repopulate a form so that users could go in and edit a form they previously submitted. The form has many fields, but, as a first step, I tried to set things up so that only the user's saved heading (from a drop-down menu) would show up correctly. I figured if I understood this, I could cobble together the balance of the code. So, I wrote this
<?php
function aModule_edit_the_ad_listing($id) {
global $user;
$output = '';
// Retrieve the listing
$listing = db_query("SELECT * FROM {aModule_listing} WHERE `id` = :id", array(':id' => $id))->fetchObject();
if (!$listing) {
drupal_goto('aModule/list_the_ad_categories');
}
// Get the headings and save which one was previously selected
$options_first = aModule_get_headings();
$selected = $listing->heading;
$form['heading'] = array(
'#type' => 'select',
'#title' => 'Heading',
'#options' => $options_first,
// Try to populate the form with the previously selected value - but this doesn't work
// because the FAPI's description for '#default_value' is 'The value of the form element
// that will be displayed or selected initially if the form has not been submitted yet'
// In this case, the form has already been submitted once
'#default_value' => $selected,