3

I developed a custom form with FAPI and added a block for it.

Block is included only on one specific page (basic node).

When user submits this form it should redirect user to external site (URL is a return value from another external site). For this purpose I've used $form['redirect'] which was working when this form was used as standalone page. In block it won't redirect and instead the same page is loaded.

I tried other methods too for redirecting such as php header location and drupal_goto but none of them work.

Perhaps there is something node level overriding that prevents the form redirect?

EDIT:

Block is a very basic implementation on code level. API based hook_info and hook_view functions accompanied with custom content function (which returns form markup:drupal_get_form('my_form')).

The redirect is defined on hook_form_submit($form, &$form_state) in which it first makes two calls to external web services and based on return values it either redirects or shows message:

// Debug shows that this evaluates true          
if (!filter_var($webservice1, FILTER_VALIDATE_URL) === false) {
    $form_state['redirect'] = $webservice1;
} else if ($webservice1 == 'ok' && $webservice2 == 'ok') {
    drupal_set_message(theme_item_list($formvalues),'status');
} else {
  drupal_set_message('Error', 'error');
}
5
  • please show your code, without it we can only guess at what is wrong
    – Geoff
    Jun 4, 2015 at 13:27
  • does the form submit, and does the page refresh? I ask because it could be assuming as a block form, it's an ajax call and thus bypassing any redirect
    – Geoff
    Jun 4, 2015 at 20:45
  • Yes, it does submit and also the page is refreshed. Referring to above piece of code I tried also drupal_set_message in place of redirect it showed status message, so it confirms that. Jun 4, 2015 at 21:05
  • are you sure $webservice1 is still returning the correct value - I don't know why it would change from a page to a block, but weird things do happen
    – Geoff
    Jun 4, 2015 at 22:35
  • If it wasn't it wouldn't evaluate true in 1st if statement. Perhaps I need to create a temporary workaround and just print that webservice URL as link in status message. Or even in a modal/popup. But the best case would automatic redirect without extra steps. Jun 5, 2015 at 6:54

1 Answer 1

0

I believe the redirect should be $form_state['redirect']

2
  • Yes it is. Like stated in the description it works that way if the form is used as standalone page. Now that it is as block content the same method doesn't work for some reason. Jun 4, 2015 at 14:45
  • in your answer you wrote $form['redirect'] instead of $form_state['redirect'] Jun 8, 2015 at 9:32

Your Answer

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

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