I have an form in a block with ajax submission. The block view code calls drupal_get_form
, adds some other info, uses a custom theme tpl to create the block.
I want to replace the form in the block with a thank you message after successful submission.
AJAX works: The ajax on the submit element of the form means that a custom ajax callback can replace the entire form with another themed chunk, passing in the form values received by the form so they can be merged in the thank you template. This works well because the ajax function has access to the form_state.
But what if AJAX is unavailable on the client? Then the normal form submit happens and the block view function just gets a blank form.
So how can my block view function get hold of the submitted values to feed them into the thank you template?
Edit: messy work-arounds
I could just access
$_POST
but that's nasty and unvalidated! yukIn the submit handler I can copy the
$form_state['values']
variable to a superglobal, and check for that.
$form_state['foo'] = 'bar'; $form_state['rebuild'] = TRUE;
in a submit handler then check for$form_state['foo']
in the form build function?$form_state['values']
; they're not supposed to be available outside the context of a form build). I wouldn't class setting a state variable as a 'workaround', I'd consider that to be the correct approach