Reputation: 385
I'm trying to transfer value "text1" from one page to another on Wordpress but can't get it working. After submit from First page to Second page Session array on second page appears to be empty.
First Page
<?php
session_start();
$_SESSION['text1'] = $_POST['text1'];
?>
<?php
if(isset($_POST['submitted'])) {
header("Location: ?page_id=5327");
} ?>
<form id="contactForm" action="http://www.bpetrade.com/?page_id=5327" method="post">
<input name="text" type="text" />
<input type="submit" />
<input id="submitted" name="submitted" type="hidden" value="true" />
</form>
Second page
<?php print_r($_SESSION); ?>
And it returns empty array on second page.
Upvotes: 0
Views: 197
Reputation: 3028
Even if you use function session_start
you will get into header already sent Warning.
So you will need to start session in init
hook check How to use session in wordpress in plugin development
Upvotes: 0
Reputation: 2719
You should start session on each page.
Just add session_start();
to first line on second page
Upvotes: 1
Reputation: 898
I think you have to start session on second page as well and your input name is text any you are trying to set $_POST['text1'] to your session variable.
Upvotes: 0