How to redirect page based on REST API call?

Hello,

I am designing a REST API tool that determines someone’s voting precinct based on the address entered into a form on our WordPress website. While I have the API working, I’m not exactly sure how to integrate it with WordPress in such a way that, after submitting the form, the user is redirected to a webpage corresponding to their precinct.

I am not much of a web dev, though I’m familiar with javascript, PHP, and WordPress. However, I have never written custom code to be used in WordPress. The person designing the WordPress portion says they typically use Gravity Forms for form submission, but we could use something else if that works better.

In researching this, it seems pretty straightforward to use WPGetAPI to call my REST API with data from the form, triggered by the form being submitted. However, I haven’t been able to find much on if WPGetAPI would be able to redirect to the correct page based on the API response. Is there a “built in” way to do something like this with either plug-in, or would I need to write custom PHP or JS code? If I do need to write code, is this something I would need to use AJAX with? WPGetAPI lets you save the response as a variable in a template tag, could I just call the wordpress redirect function using this, or do I need to account for the fact this is an asynchronous call?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer