I have the following pages:
webservice.php - it has a webservice used to handle all the possible GET and POST variables sent to it, returning a string as result.
form_page.php - the page with a form whose action redirects to table_result.php.
table_result.php - on this page, there is a table which should be filled up with the results from webservice.php.
My question is: if the GET/POST variables' values are only available on table_result.php (after the form data has been submitted), how can I send them to webservice.php and get the result to fill up the table without leaving table_result.php? IT is important to note that on webservice.php there are a bunch of if (isset($_GET["var_name"])) to formulate a database query and return the result on a string, as said before.
Thanks in advance.
First, instead of the $_GET, use $_REQUEST, as this would make it available via both POST and GET. Then you can just use the search here and find your answer
Related
I am fairly new to using PHP so bear with me if this is a stupid question
I have a form that comprises a number of radio buttons, the action is set to redirect to the same page and the method is GET.
A click on a radio button gets data from the database. The data is used to redisplay the same page with changed content.
The page URL has PHP arguments in it like the example below
localhost/basesite/mypage.php?itemID=8&name=city&number=9
When I access the page and click on a radio button I get a page with “no arg” because the URL reads
localhost/basesite/mypage.php?number=6
Two of the arguments are missing and that the last one is incorrect.
With no change whatsoever to the code except using ”post’ instead of “get” the whole thing works flawlessly.
I have used
form action= "" method=“get”
form action= “#” method=“get”
and many other actions using $_SERVER["REQUEST_URI”], $_SERVER['QUERY_STRING'] etc and combinations thereof.
Those that worked with POST did not work with GET.
I do not need to use POST as data is not written only retrieved from the database so I have no worry about data being written more than once.
If I have to I will use POST but if the user refreshes or uses the back button then the usual warnings will be issued by the browser.
What am I missing?
you should you use $.get which is a jquery method.
First, you should share your full source code for better understanding your problem. And also you have to use post method to submit a radio button values to get some value from your database. Form data can be submitted using these two methods (get and post). Both are used for the same purpose, but stands apart under some specifications. As in GET method key values are passed in the Url while in POST, the information transfers in a hidden manner.
Sorry folks. It was a badly formed URL due to me not fully understanding how to set a hidden element.
I'm working on big site and it has filtering of cars in it. I'll explain how the form filtering works:
so the user chooses filter options, car number and so and presses go, which makes GET request to server (php) i've changed every variable from $_GET to $_POST and changed form submission method, the problem is that when form returns big number of items it might have more than 2 pages, so when the user clicks on second or third page all this code does is add page number to the request like this: www.example.com/GET_REQUEST_VARIABLES -> www.example.com/pagenumber&GET_REQUEST_VARIABLES. that way server returns second page items and so.
but when i send post request, it isn't saved in the url so server doesn't know what to return,
can you help me solve this problem?
i can explain better if you ask questions i don't know if i explained clearly here
Is there a reason you are using POST instead of GET? Using GET is more SEO friendly in this case. And since you aren't sending sensitive data in the form submission, I don't see a reason to use POST. Another advantage of using GET is that you can directly link to search results. (For instance, if I search for a Honda Fit, and want to show my wife, I have a direct link to the page)
(Look HERE for a bullet-point explination of the difference bewteen POST and GET).
To answer your other question, POST does not use the URL. Only GET does So if you need the form data to be serialized into the URL, you'll need to use GET. Since you changed the form submission method to POST, you'll need to change the server side logic as well to accommodate. I can't be of much use without knowing what server-side technology you are using. Assuming you are using PHP, you could start here
If you aren't much for MAN pages, just change all the $_GET['fieldName'] calls in PHP to $_POST['fieldName']
You could always POST the first page, and use GET ONLY for the page number. In the form you would just do this
<form method="post" action="www.foo.com/search?page=1">
Then you can store your POSTed variables into the $_SESSION super-global. BOOM. POSTed pagination. It would be a breeze to render it on the fly with PHP
$nextPageURL = 'www.foo.com/search?page=' . $_GET['page'] + 1;
if($_GET['page'] !== '0'){
$lastPageURL = 'www.foo.com/search?page=' . $_GET['page'] - 1;
}
Assuming I have a two pages (page1 and page2), there are variable values I want to send to page2 without using $_GET function but instead $_POST through a url.
Example on page1
<?php
$name="Dman";
$id="12";
$level="122";
?>
Goto Page2
On page 2, I want to receive the variable values using POST.
name:dman
id: 12
level:122
UPDATE
Please what I am trying to achieve, is to prevent showing items being transmitted from one page to the another, when url is been used. I read some blogs and they are like, using POST workaround can help achieve this.On the contrary if there is a way to avoid using "?id=$id&name=$name" on a url but still receive your variables on the next page, I would be grateful to know.
Thanks for helping
You need to use the GET method if you want to pass parameters in the URL. POST is a different method and it's not possible to represent or reference POST data in the URL.
Some reading on the definition and difference between post and get: http://www.w3schools.com/tags/ref_httpmethods.asp
The GET method pass the parameters INTO the url, for example :
http://your/path?yourvariable=value
The POST method hide the parameters from the url.
The simplest way to pass parameter with POST method is to make a HTML form. In your Php sript, you can access to this value with the $_POST superglobal array.
I have a table in a php document. It has a button with calls a function in an external javascript file, which calculates values and returns them to the table using document.formName.varName.value=jsVarName;
and then calls the
document.forms["formName"].submit()
method which should then send the new values to the same php page using
(form name="formName" action="pageName.php" method="post")
at which point I expected to be able to use
if(isset("submit")){ $phpVar=$_POST["tableVarName"];
to then access the newly calculated values. Unfortunately, when I try this, there appears to be nothing in the $_POST variables. Do you have any idea where I'm going wrong? I can post code snippets if that would help.
Did you get anything with $_REQUEST or $_GET? Maybe your form is not being submitted as post. Just a guess!
My problem is that the back button causes the browser to say something like "Page expired" when the previous page was created by a form.
Example:
page1: form submitted with search
criterias ($_POST request, form
points to page2)
page2: Receives $_POST request and
show result (list of user with links,
points to page3)
page3: Show user profile
Now when the visitor clicks the back button in the browser it will show something like "Page expired".
Instead the previous page should be shown with no warnings (page2, with the userlist)
How are your strategies to get around this behavior?
If you are submitting a form with search parameters, you are trying to get some data, not modify some.
So, you should use the HTTP GET method, and not POST : POST should be used when you intend to create/modify data, and GET should be used when you intend to fetch some data.
Or, if you have some create/modify operation that has to be done :
The form first POSTs to a first page
That page does some operations (like writing something to a database)
And then redirects to another page, using a Location HTTP header.
It's that last page, that's queries by the browser using a GET requests, that displays the data fetched from the parameters received in the URL.
See the Post/Redirect/Get page on wikipedia, about this.
Use the Post/Redirect/Get (PRG) Pattern.
This applies to PHP and IE8.
Not only must you set cacheing to private, but you must remove the 4 cacheing headers and this can only be done with PHP 5.3. In PHP 5.2 you can only set the 4 headers to blank values if using the Zend Framework's setHeader() method. For some reason is not sufficient on IE8 to set the 4 header values to empty values. Here's the code for PHP 5.3:
header_remove("Expires");
header_remove("Cache-Control");
header_remove("Pragma");
header_remove("Last-Modified");
Send a Location header in the script you POSTed to, pointing to the page that comes after.
Don't use POST for search. Search can safely be done with GET since it won't alter anything.
You can use session to do this.
eg.
$_SESSION['name'] = $_POST['name'];
Remember to unset your variables after the process is complete to optimize memory usage.