1

when a form action takes place, it posts the fields and also redirects to that page, right? I need to make a custom form do the same, I have successfully made it post the fields in my drupal 8 custom module , using an http request with guzzle, but how do i make it redirect simultaneously as well?

closed as off-topic by kiamlaluno May 12 at 12:24

  • This question does not appear to be about Drupal within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I'm voting to close this question as off-topic because it is about code the OP wrote but that isn't shown. For questions about code, we expect the question to show the code. – kiamlaluno May 12 at 12:24
1

In your submit handler:

$form_state->setRedirect($route_name, $parameters, $options);

Or if you have a URL object:

$form_state->setRedirectUrl($url);

Reference:

  • Hi thanks, if I just have the URL as a string, what parameters and options do I have to put in? – Diana May 5 '17 at 15:03
  • 1
    Something like $url = \Drupal\Core\Url::fromUri('http://google.com'); – Clive May 5 '17 at 15:07
  • I gott this error Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it. – Diana May 5 '17 at 15:10
  • Oh yeah, I forgot about the unwilling API. See this comment: drupal.org/node/2599342#comment-10484496 for a code example, but read the rest of the issue for context too – Clive May 5 '17 at 15:13
  • I tried this but my response is a guzzle object, so it doesnt like it $form_state->setResponse($response); – Diana May 5 '17 at 15:23

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