-2

loaded page from javascript. tested for GET & POST. Only GET set as expected;

window.location.href = "medications_edit_revised.html?recordId="+id ;

Retrieved and used the data from the GET[]

Reloaded page from SUBMIT as shown below.

    <form method="post" action="">
<table id="detailsDivTable">
    <?php
$editClass->selectTheRecord();
    ?>
</table>
<fieldset name="Group1">
<legend>Group box</legend>
    <input name="saveButton" type="submit" value="Save" />
    <input name="deleteButton" type="submit" value="Delete" />
    <input name="cancelButton" type="submit" value="Cancel" />          
</fieldset>
</form>`

Tested GET[] & SET[]

    if  (isset($_GET['recordId']) ) {
    $recordId = $_GET['recordId'];
    require_once "medications_edit_revised.class.php";
    $editClass = new editRevisedClass($DBH, $recordId);
    }

    if(isset($_POST['saveButton'])) {

Both tested TRUE. Is this normal behavior. I expected the GET[] would have been cleared when the form was POSTed

If yes is there a way to clear the GET before sending the SUBMIT

Thanks

  • 1
    Welcome to SO. Please read: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and also [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) - You need to show us your code for us to be able to understand what it does and what you need to change. Otherwise, all answers and suggestions will be pure guesswork. – Magnus Eriksson Aug 18 '18 at 19:23
  • yes, it depends on the stitution – Dean Aug 18 '18 at 19:51

3 Answers3

0

You seem to be confusing POST/GET requests and the PHP $_POST and $_GET superglobal variables.

PHP will populate $_GET with data in the query string of the URL the request was made to.

PHP will populate $_POST with data in the request body of a POST request if that data is encoded using a supported encoding.

It doesn't matter if the request was caused by JavaScript, a form submission, or something else.

Is this normal behavior.

Yes

If yes is there a way to clear the GET before sending the SUBMIT

Submit the form to a URL which does not have a query string.

The URL the form is submitted to will be specified by the action attribute.

If you don't have an action attribute, it will be submitted to the URL of the current page. If that URL has a query string, then so will be the URL that the form is submitted to (and thus $_GET will be populated).

If you want to avoid that, then specify the action explicitly.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
0

When you set the URL like this:

window.location.href = "medications_edit_revised.html?recordId="+id ;

You have set URL params. Then when you do this:

Reloaded page from SUBMIT as shown below.

<form method="post" action="">

Because the action is empty it'll retain the URL parameters, because that's what empty and (eg) $_SERVER['PHP_SELF'] do - they send to the current URL, params and all.

You already know the URL so just set it as needed:

action="medications_edit_revised.html"
Community
  • 1
  • 1
James
  • 4,317
  • 4
  • 33
  • 45
-2

Can you please past some of your code?

If you use GET to revice your variable, it gets it from the URL: example.com?name=jesper&lastname=kaae

The differences is:

GET requests a representation of the specified resource. Note that GET should not be used for operations that cause side-effects, such as using it for taking actions in web applications. One reason for this is that GET may be used arbitrarily by robots or crawlers, which should not need to consider the side effects that a request should cause.

And

POST submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both.

You can read more about them here

Jesper Kaae
  • 128
  • 1
  • 9
  • 1
    This doesn't really answer the OP's question, though. It only explains the differences between GET and POST. As you self point out, the OP needs to share their code. Before that, no one can give the OP a proper answer. – Magnus Eriksson Aug 18 '18 at 19:55