Hi everyone,

I'm converting one of my custom modules form version 5.x to 6.x and having some issues with the Forms API.

I have a form that offers criteria selection. After selection and submission, the page reloads with the same form and reflects current selections + outputs the data based on the selected criteria. After upgrading to v6.x - everything works, except when the form is submitted and page reloaded, the form doesn't reflect the currently selected options - all selection are reset to the default state of the form.

I need selections to stay in the form after it's being submitted. Any ideas on how to fix that?

Thank you.

Comments

jaypan’s picture

Add $form_state['rebuild'] = TRUE to your submit function.

Contact me to contract me for D7 -> D10/11 migrations.

gemini’s picture

Yes, I have relocated that part from the form constructor function in version 5.x to form_submit in v.6.x, but that didn't help.

gemini’s picture

Got it to work by adding $form_state['redirect'] = FALSE; instead of 'rebuild'

mag2000’s picture

It display the form when i select the drop down it go to default value it is not remain on last selected option

$output .= drupal_get_form('formexample_testform');

echo $output;

function formexample_testform() {
$myvalue=array();
db_set_active('mydb');
$result = db_query('SELECT maincode,subcode,cname FROM {company}');
while ($row = db_fetch_array($result)) {
$arrayvalue=$row[maincode]  . '+' . $row[subcode];
$myvalue[$arrayvalue]=$row['cname'];
}
db_set_active('default');
$form['select_company'] = array(
'#title' => t('Select Company'),
'#type' => 'select',
'#description' => t('Pick the company your want to do analysis.'),
'#options' => $myvalue,
'#multiple' => FALSE,
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Apply')
);
return $form;
}

function formexample_testform_submit($form_id, $form_state) {
$form_state['redirect'] = FALSE;
}
thtas’s picture

I'm having the same problem, did you fix it?

Just simple form with $form_state['redirect'] = FALSE in the submit handler.

I submit the form and all the values are lost.

I've experimented with $form['#redirect'] = FALSE and it doesn't help.

Having to explicitly set the form default values if the form_state values exist is tedious :\

christopherhanson’s picture

if you put this in the actual form and not the form submit function it does work and keeps the values on refresh - big help to me thanks! been struggling with this for a while!