Search code examples
drupal-6drupal-fapi

drupal6 submit to third part site with internal redirect


I'm trying to submit a drupal 6 form PIA to a third party site for processesing, but after submitting the form, I need to redirect to a thank you page within my own site.

I've read this post - Drupal form submission to a 3rd party website

but i'm nor sure how to set up the redirect properly. this is my code:

$form_state['#action'] = 'external site.com';

$form['#redirect'] = 'thankyou.com';

thanks


Solution

  • Make sure the redirect is the last step. Something like this:

    function my_module_form {
      $form['#action'] = 'some.external.site';
    
      # Store the redirect in a value element, maybe we need some data
      # which are passed to the form, like a user ID, node ID etc.
      # So lets store the link in a value element
      $form['redirect_link'] = array(
        '#type'  => 'value',
        '#value' => url('some.redirect.page'),     
      );
    }
    
    function my_module_form_validate ($form, &$form_state) {
      # Do some validation stuff...
    }
    
    function my_module_form_submit($form, &$form_state) {
      # show some confirmation message...
      drupal_set_message(t('Successfully sent your data into space.'));
    
      # And finally the redirect...
      # The 'redirect_link' value was passed internally, without being sent
      # to the browser so we can safely use it.
      $form_state['redirect'] = $form_state['values']['redirect_link']
    }