The values of the parameters in the query string are dynamic, if they are supplied and run from the address bar of a browser
a message get sent.Now, what i want to do is create a form, get the values for the parameters from the form and pass them to
the http API via a php script, and have it run in the background instead of typing them directly to the address bar.
The if statement checks whether the superglobal ‘username’ is set or not, if not it will display an error message. If it does then the ‘else’ part is used to process the desired code.
Its an existing API for connecting to a web sms server and sending sms once you supply the correct values in the query string. The values vary from user to user-dynamic.
The challenge is how to submit values from a form to the API within a script without having to type the whole thing into an address bar.
If you want something super simple and quick, and if you’re the only person who’s going to use it, you can just create a form with the action set to the URL of the API. logic_earth explains this quite well.
The issue with this, the reason you can only use this option if you’re the only one using it, is that once you submit the form you’ll end up on API’s domain and all you’ll see is the response of the API, be it XML, JSON or whatever.
If you need to stay on your on application and want to display a human-friendly page/message you’ll need to submit the form to a PHP script that takes the values of the input fields of the form and submits it to the API. Then according to the response from the API you can display various messages. For this you might want to look into PHP’s file_get_contents() function. There are other methods too but this is the simplest one and should be sufficient for what I think you are trying to achieve.