I have received the following response from an API.
[{
"BookId":"32c03594-1ecb-4f97-8453-5b28a03d26d9",
"BookName":"Book1",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"51d16696-b98a-4b3b-ac67-f36559cff70b",
"BookName":"Book2",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"7b557a75-bf5e-4c29-9f31-43a7fee77520",
"BookName":"Book3",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"c945ade5-d540-4378-9979-3842a1da396b",
"BookName":"Book4",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"814869e2-e5af-48bc-a6da-28f272366955",
"BookName":"Book5",
"Bookstatus":3,
"Country":"AU"
}]
I have a webform with drop down box to choose the book you want.
What I want to happen, is when you click submit you are sent to another page, and on that page I want to be able to access the BookId
, BookName
and access token from the first page via $_POST
. I have no trouble with the BookName
but can't work out how to get the BookId
and access token to go with it.
This is what I have so far:
Please note: the access token was obtained with $_GET
in the head of the page and assigned to $access_token
variable.
<body>
<?php
$array=json_decode($response, true);
$arr_len = count($array);//length of the array = 5
$for_len = $arr_len - 1;//length - 1
?>
<h1>CashBooks</h1>
<form action="getcoa.php" method="post">
<select name="books">
<?php
for($i=0; $i<=$for_len; $i++){
$bookname = $array[$i]["BookName"];
echo '<option value="' . $bookname . '" name="' . $bookname . '">' .
$bookname . '</option>';
};
?>
</select>
<input type="hidden" name="<?php $bookname; ?>">
<input type="hidden" name="<?php $access_token; ?>">
<input type="submit" value="Get Chart of Accounts">
</form>
</body>
With the BookId
, I haven't figured out how to deal with that yet, so any suggestions would be great. And what I'm trying with the access token doesn't work. When I click submit with things how they are, I get this error on the "getcoa.php page":
"Notice: Undefined index: access_token in C:\wamp\www\getcoa.php on line 6"
This is line 6:
$access_token = $_POST['access_token'];
FYI. The token part is solved.
But I dont think I have been clear on what I'm trying to accheive with BookId. On this page, the only thing the "USER" will see is a drop down menu with a list of BookNames, from which they select ONE, and click a submit button... On the next page, I will make a call to an API endpoint, but I need the BookId to call on that endpoint.
So the BookId for the selected BookName is needed to be somehow posted to the next page, so I can use $_POST on that page to get the BookId and use it to access the endpoint desired, without the end user knowing "BookId" exists in anyway.
Hopefully I have been more clear on what I'm trying to achieve. Sorry if I wasn't to start with.