I have used the following code on submit of a form to first send the form contents via guzzle and then redirect the form. I get the error
Error: Call to undefined function TrustedRedirectResponse()
this is my code:
use Drupal\Core\Routing\TrustedRedirectResponse;
function mymodule_submit(&$form, FormStateInterface $form_state){
$url="xyz.com";
$post_data=array("color"=>"red");
$client = \Drupal::httpClient();
$response = $client->request('POST', $url, [
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
'verify'=>false,
'form_params' => $post_data,
]);
$status = $response->getStatusCode();
$response = TrustedRedirectResponse(Url::fromUri($url));
$form_state->setResponse($response);
}
I have two questions - how can I avoid the error , and is the order of getting the guzzle response and then getting the redirect response the correct order?