Getting the value from a form using if-else and use it to call API

I want to know if its possible to get the value from a form if I click the submit button. My code works when I change the variable $page it will call the current $page number in the API through the list of pages, now I want to initialize the variable $page using a form input/button value but I can’t seem make it work. I should get $page value first before calling the API

  1. Get the $page from the form data (if it is >=1) or use 1 if there wasn’t a valid number given
  2. Call the API with the page number
  3. Show the results like normal
  4. In the form, if $page > 1 then show the Prev button, and if $page < number of pages then show the Next button
  5. For the two buttons, give them a name of “page” and a value of $page - 1/$page + 1 appropriately: when someone clicks either button then that will submit a “page” in the form data for your code to use

Any help, suggestion or example is greatly appreciated. PHP Code || API

When/where is $page defined? Upon form/page submission?

Your not providing any real info that bearing on the answers.

You are talking about front end (buttons)… and then backend variables ($page)… but have not shown anyone how this is set.

In theory, this should be a very easy issue to address, but we have no background to guide you.

I would guess that upon some sort of button press/page submission, you take some sort of $_POST[] value and then do some conditional checking and then set the $page variable to whatever value to meets the scenario.

Sponsor our Newsletter | Privacy Policy | Terms of Service