0

In the following code, I am trying to update the underlying form to a new value, but the value does not seem to update properly.

function msul_tgif_xml_basic_search_form_validate($form, &$form_state) {

  //$Offset is computed properly as verified by dpm.

  $form_state['complete form']['SearchOptions']['Offset']['#value'] = $Offset;
}

function msul_tgif_xml_basic_search_form_submit($form, &$form_state) {
  $form_state['rebuild'] = TRUE;
}

When I return to msul_tgif_xml_basic_search_form, $formstate['values']['Offset'] properly shows the new computed value, but when I recreate the form with the new value, it does not update properly. The relevant portion of the msul_tgif_xml_basic_search_form function is:

      $form['SearchOptions']['Offset'] => [
                    '#type' => 'textfield',
                    '#title' => t('Start with result:'),
                    '#required' => FALSE,
                    '#default_value' => 
                         isset($form_state['values']['Offset']) ?
                         $form_state['values']['Offset'] : 1,
                    '#size' => 6,
                    '#description' => t('blah'),
                    '#element_validate' => [
                              'element_validate_integer_positive'
                    ],
              ];

As I said, the regenerated form still contains whatever the user typed in last and does not update according to what the code is telling it. Any ideas of what I am doing wrong...I have spent about 25 hours trying to get this to work.

I have tried the above, I have also tried form_set_value().

1 Answer 1

0

I don't feel this is the right answer, it seems like a kludge but it does work, I changed the value of $form_state['input']['Offset'] and that worked. Hopefully this helps someone else as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.