I am encountering a CORS warning issue in the browser console when attempting to redirect to an external URL using a custom form action. The redirection is initiated within the run() function.
Here's the scenario I'm facing:
Upon submission, the form sends an API request to a third-party server.
The third-party server responds with a URL.
The intention is to redirect the user to the provided URL.
Below is the relevant code snippet that demonstrates the issue:
<?php
class MyFormCustomAction extends \Breakdance\Forms\Actions\ApiAction
{
public static function name() {
return 'My Form Custom Action';
}
public static function slug() {
return 'my-form-custom-action';
}
public function run($form, $settings, $extra) {
$response = wp_remote_post( $endpoint, $args );
$theURLtoredirect = json_decode( wp_remote_retrieve_body( $response ) );
wp_redirect( $theURLtoredirect );
exit;
}
}
Screenshot of the error ( assumes the link https://example.com is the URL returned by the server ):
I am seeking guidance on the proper way to handle this situation and resolve the CORS error during the redirection process.
I am encountering a CORS warning issue in the browser console when attempting to redirect to an external URL using a custom form action. The redirection is initiated within the
run()
function.Here's the scenario I'm facing:
Below is the relevant code snippet that demonstrates the issue:
Screenshot of the error ( assumes the link
https://example.com
is the URL returned by the server ):I am seeking guidance on the proper way to handle this situation and resolve the CORS error during the redirection process.