0

I am doing a custom module in Prestashop. In the module frontend I have the smarty form. Inside the smarty form there are some input fields with the submit button. I want that when user enters the values and click on the submit button then those values should be submit to one remote server same like the php curl does. So can someone tell me how to send those values to the remote server and show the response from the server?

Any help and suggestions will be really appreciable. Thanks

NewUser
  • 12,713
  • 39
  • 142
  • 236

1 Answers1

0

To do such a thing your best call is probably to use Ajax with a controller which will be used as your Ajax endpoint url.

There's many examples on how to do this in PrestaShop, here's one:

The JS: https://github.com/PrestaShop/gamification/blob/master/views/js/gamification_bt.js#L167-L184)

The controller: https://github.com/PrestaShop/gamification/blob/master/controllers/admin/AdminGamificationController.php#L302-L312

You pass all the values of your form through ajax to your controller, then - from this controller - you call your remote server with php Curl and finally you send a response back to your ajax callback, and display everything you want to your user.

Related reading: http://api.jquery.com/jquery.ajax/

Another option would be that your Remote server accept "Cross Domain Origin" (Related reading: Cross domain xmlhttp), but that imply that you can yourself your API endpoint, if you can't first option is the way to go.

Hope this helps !

Community
  • 1
  • 1
tchauviere
  • 61
  • 5