Form submission not saved when using a dynamic redirect I have forms where I use a form alter to set various form fields on the fly.
One of which is the Thank You page field that a user should go to after submitting.
Example $form['submitted']['thankyou_page']['#value'] = 'my_page';
I use the same form for multiple reasons so setting the thank you page to suit.
After setting these (which work fine) I then enter a function to do some processing of the form fields to a CRM.
The final section of this function is like this
try {
    $result = $client-&gt;CreateContact($data);
} catch (Exception $e) {
    $result = $e;       
}
  my_submit_handler2($values['thankyou_page']); // redirect
}
}

The processing works fine to CRM but my problem is that the form submission (result) doesn't save in Drupal and the auto-emails after submit fail to send too.
The redirect is done like this
function my_submit_handler2($f) {
  drupal_goto($f);
}

So I guess the submission is being interrupted?
How can I do these redirects without affecting the flow of the form submission?
A form submission handler, as well a form validation handler or a hook to alter a form, should never call drupal_goto() since it outputs a HTTP header and interrupts what Drupal is doing.
The correct way to redirect a form from a form submission handler is setting $form_state['redirect'] in Drupal 7, or calling $form_state-&gt;setRedirect() in Drupal 8. The alternative for Drupal 8 is calling $form_state-&gt;setRedirectUrl().
For Drupal 7, the following code would redirect the users to node/123?foo=bar#baz.
$form_state['redirect'] = array(
  'node/123',
  array(
    'query' =&gt; array(
      'foo' =&gt; 'bar',
    ),
    'fragment' =&gt; 'baz',
  ),
);