0

So, this is what I'm trying to do. I've got a webform submission filled in and saved to the database. When viewing the submission (node/nid/submission/sid). I want to show a form, which ask the user for a key. When the key is filled in I want to change the display of the submission (not the data in the database) using the webform_submission_load() hook. This is the code right now:

// webform hook
function mymodule_webform_submission_load($submissions) {
   $key_status = mymodule_get_key_status();
   if($key_status) {
      //change the submission display values
   }
}

// return TRUE or FALSE, depending on form submit
function mymodule_get_key_status($setkey = FALSE) {
   $status = &drupal_static(__FUNCTION__);
   if(!isset($status)) {
      $status = $setkey;
      // display form when key is not provided
      if(!$status) {
         $getform = drupal_get_form('mymodule_form');
         $output = drupal_render($getform);
         drupal_set_message($output, 'form', FALSE);
      }
      // key provided in form, so don't display the form
      else {
         $errors = drupal_get_messages('form');
      }   
   }
   return $status;
}

// form submit callback 
   function mymodule_form_custom_submit($form, &$form_state) {
       if (isset($form_state['values']['form_value'])) {
          $key = $form_state['values']['form_value']);
          drupal_static_reset('mymodule_get_key_status');
          mymodule_get_key_status(TRUE);
       }
    }

When viewing a submission I see the submission and the form. When I submit the form nothing changes and the form is displayed again. When I debug the return value of the mymodule_get_key_status function the following happens. First the function return FALSE, then the form calls the function and the function returns true. After that the function is called again by the webform hook. The function returns false again... Not what I expected. When I call mymodule_get_key_status(); in the form submit callback it returns true. So the drupal_static is set properly.

Why isn't the code working as I expected?

1 Answer 1

0

Well, i figured it out myself. After the form submit callback drupal fires a redirect to the same page. So the values set in mymodule_get_key_status are flushed after the redirect. I add $form_state['redirect'] = false; to my submit callback and now everything works as expected.

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.