0


Im using wordpress
I wanted to send the data that is collected by form in the first page to the next page
I didn't find anything that can send array data to another page other than GET command, GET commands uses URL, The reason I'm not using this GET is the sending information includes price values that are calculated using entered information

I found this $_session seems ok to my case (If any others are available, please tell me), Used wp session manager plugin to use $_SESSION.
im using it like this,

if(!isset($_SESSION)){
    session_start();}

if(isset($_GET['B2'])) {
$_SESSION["info"] = "user-form";
$_SESSION["weight"] = $weight;
$_SESSION["price"] = $weight;
buy_now(); }

The B2 is a buy now button

function buy_now(){
 if(isset($_GET['B2'])) {
 header("Location:".get_site_url()."/buy-now/");
 } 

 if(!isset($_SESSION)){
    session_start();}
        echo $_SESSION["info"]."<br>";
        echo $_SESSION["weight"]."<br>";
        echo $_SESSION["price"]."<br>";
 }

The weight and price are Undefined index, the info will display.
What is the problem here? and How can I send variables to another page?, I'm unable to find any solution for now. Please help with this...
Thank you

ltsharma
  • 83
  • 9

4 Answers4

1

whenever you are need to check the session is start of not you should not check ist with $_SESSION you need to check the session_id() is generated or not (check the post for check the session start Check if PHP session has already started)

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
if(isset($_GET['B2'])) {
   $_SESSION["info"] = "user-form";
   $_SESSION["weight"] = $weight;
   $_SESSION["price"] = $weight;
   buy_now(); 
}
Community
  • 1
  • 1
Parag Chaure
  • 2,883
  • 2
  • 19
  • 27
  • Actually i was not checking whether the session is set or not. i just set the session and tried (that's not a problem here). Anyways thats for showing how to check session. In my case it worked for string "info", but its not showing variables ("weight" and "price") in next page. – ltsharma Jul 27 '16 at 09:47
0

word press provide another method like wp_cache_get / wp_cache_set

which you can use as own CMS method for passing data from one page to another page by define expiry time as well.

wp_cache_set

wp_cache_get

Ashish Patel
  • 3,551
  • 1
  • 15
  • 31
0

I think you have to try POST method.

    <form action="test.php" method="post">
      <input type="text" name="my_value" value="value"/>
      ...
    </form>

On next page

    <?php echo $_POST['my_value'];?>

That's it.

Shahid Latif
  • 135
  • 1
  • 6
  • Thank you. Actually, POST was my first try. im getting all the required form values using post only (before sending it to next page) and i tried accessing post values through `` in next page but result was "Undefined index". – ltsharma Jul 27 '16 at 09:41
0

Refer https://codex.wordpress.org/Class_Reference/WP_Object_Cache for detailed explanation and remember to delete / reset as per your use case else might be a problem.

iSensical
  • 747
  • 5
  • 8