Jump to content

Trying to clear $_POST


Recommended Posts

Typical situation that is called Post/Redirect/Get.

 

I have a custom product details page based on the WHMCS sample provisioning module.

https://github.com/WHMCS/sample-provisioning-module

 

I have a form in product details area that posts data into

function provisioningmodule_ClientArea($params)
.

 

The problem is that I cannot clear $_POST information afterwards. So when the browser is refreshed the $_POST data is resent.

 

The typical method to get around this as found on the internet is to use

header("Location: " . $_SERVER['REQUEST_URI']);

exit();

 

That should reload the browser, clear $_POST, and return me to

/clientarea.php?action=productdetails&id=xxxx
. However it takes me back to
clientarea.php?action=services
.

 

Can't figure out why. The 'REQUEST_URL is correct but WHMCS doesn't like it for some reason and goes back to clientarea.php?action=services

 

unset($_POST) and $_POST = array(); doesn't clear it because it needs to be cleared from the browser not in PHP.

Edited by mustardman
Link to comment
Share on other sites

I figured out how to get around it. I think WHMCS needs $_POST if you are staying on the same page because it includes the service/product ID.

 

I ended up creating a variable in $_SESSION to track when a form has been posted once so it's not posted a second time on browser refresh.

 

if ($_SESSION['submitted'] == 1 && !isset($_POST['customformdata'])) {

unset($_SESSION['submitted']);

}

..

..

if ($_SESSION['submitted' != 1]) {

//Do some stuff with $_POST custom form data

$_SESSION['submitted'] = 1;

}

 

Edited by mustardman
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated