3

I want to redirect a page and attach POST params and Custom headers to it e.g.

$data_to_post = array();
$data_to_post['CAPA_Type'] = "createPlan";
$data_to_post['CAPA_Gateway'] = "PayStack";

$headers = array();
$headers[] = "CAPA_token: xxxxxxxxxxxxxxxxxxxx";

Submitting a form dynamically from JS doesn't work, because it cannot send custom headers, AJAX is not an option as I want to open the url in browser not in the background. Is it possible to achieve this in JS or PHP? If it is, how would one go about doing it?

mega6382
  • 9,211
  • 17
  • 48
  • 69

1 Answers1

2

You can not do this as you want, further possible solutions are using php cURL or Carl McDade's answer or what I describe below.

You can do this as well->

  1. Submit your form to a php page where you can make a hidden-form with your POST params,
  2. onload of this PHP page submit the hidden-form (to the URL where you want to redirect) using JS form.submit().

Just like we see this in case of payment gateways, also everything will happen in synchronous(not in background) manner.

Ultimately you will be on your final page with POST params and custom headers.

Thanks

Community
  • 1
  • 1
Hirdesh Vishwdewa
  • 2,334
  • 1
  • 19
  • 33