I would like to build a PHP form pulling data using an API.
I have an API key and secret. I have done some basic test queries by manipulating the URL to make sure everything works and it does.
What I don’t know how to do is build the PHP form and display the results. I was going to do it in JS however then the API key and secret would be revealed in the URL and there are multiple search options.
From what I have seen with other people asking about php and api the connection would be like this:
$apikey = 'xxxx';
$secret = 'xxxx'
$service_url = 'https://website.com/' .'api_key=' . $apikey . '&api_secret='. $secret. ‘&’ .$criteria . ‘&’ . $criteria2 . ‘&’ .$criteria3;
This is the API URL I use for testing:
domainnamehere/clients/api/search?api_key=1234&api_secret=1234&state=nsw&given_name=john&surname=smith
The results in json look like this:
[{"state":"NT","date":"2016-08-17","listing_type":"listing info","place":"place info","moreinfo":"","name":"SMITH Dale John","location":"Darwin","file":"1234","additional_info":"1 did something stupid"},{"state":"NT","date":"2016-08-03","listing_type":"listing info","place":"place info","moreinfo":"","name":"SMITH Dale John","location":"Katherine"," file":"4567","additional_info":"1 did some more dumb stuff;2 did even more dumb stuff;3 really dumb stuff;4 even more dumb stuff"}]
I have a basic understanding with PHP search forms however this appears to be well over my head. I am guessing it is going to be a mixture of submitting a query and pulling down data and formatting it.
What I am looking for is an answer on how to build this form. It will be a search form I put on a website and have the results displayed on the same page.
So it would look like this:
Search form:
Name: "enter name" Surname: "enter surname" State: "enter state"
Results.
State: QLD
Date: 01/01/2019
Listing Type: listing info
Place: Place info
More Info:
Name: Smith Dale John
Location: Darwin
File: 1234
additional_info: 1 did something stupid
State: QLD
Date: 01/01/2019
Listing Type: listing info
Place: Place info
More Info:
Name: Smith Dale John
Location: Darwin
File: 1234
additional_info: 1 did something stupid
2 did even more dumb stuff
3 really dumb stuff
4 even more dumb stuff
I know the search form itself should be relatively simple to do as it is just going to insert the form fields into the url.
But how to pull back the data from that url generated from the form submission and display them?