Trying to transfer a value from one page to the next
Posted: Sun Aug 26, 2007 2:20 pm
Hi
I've been working in php now for about 1 year, trying to teach myself. I took a 4 day php class but that just made me realize how much there is to learn. The mud is clearing very very slowly. I've been basically doing trial and error editing, tweaking my Wordpress 2.1 and because it is just too time consuming to keep trying to go it alone, I finally registered here.
So this is what I am trying to do right now.
I have a page that displays a sigle post in Wordpress. One of the template tags is:
This tag represents the id of the post. I want to transfer this id and use it on the login page which also acts as a registration page when action=register is called.
My objective is to have the id populate the field at all times. Sometimes people might click submit without filling out all required fields. I found that the_ID would not repopulate when that occured.
So what I did was create a link:
Then on my login page, I add at the top of the file:
I also add a new field within the registration form:
(I want to associate the_ID of the post for those that registered through it so eventually I have to get this in the database - but thats a hurdle I'll deal with later.)
I've looked into the sessions idea and tried to do the session_start on the post page because it just seems more logical and reliable. But the php function for "the_ID" starts within the loop and the session_start begins before any headers or functions.
How do I get the value of "the_ID" in the session_start from that same post page so it can be used in the pages that follow? (The id changes for each new post)
Is this the most efficient way to handle this?
Is there any problem with the way I did it?
My php info:
PHP Version: 5.1.6
Display Errors: On
Error Level: Not E_ALL
Register Globals: On
Thank you for helping. I hope someday I'll be able to give back.
I've been working in php now for about 1 year, trying to teach myself. I took a 4 day php class but that just made me realize how much there is to learn. The mud is clearing very very slowly. I've been basically doing trial and error editing, tweaking my Wordpress 2.1 and because it is just too time consuming to keep trying to go it alone, I finally registered here.
So this is what I am trying to do right now.
I have a page that displays a sigle post in Wordpress. One of the template tags is:
Code: Select all
<?php the_ID(); ?>My objective is to have the id populate the field at all times. Sometimes people might click submit without filling out all required fields. I found that the_ID would not repopulate when that occured.
So what I did was create a link:
Code: Select all
<a href="http://www.mysite.com/login.php?action=register&postid=<?php the_ID(); ?>">Register</a>Code: Select all
<?php
session_start();
$_SESSION['postid'] = $_GET['postid'];
$registeringpostid = $_GET['postid'];
ob_start();
and then some other code...Code: Select all
<p>
<label><?php _e('ID #:') ?><br />
<input type="text" name="postid" id="invite" class="input" value="<?php echo $registeringpostid ?>" readonly="readonly" size="20" tabindex="10" /></label>
</p>I've looked into the sessions idea and tried to do the session_start on the post page because it just seems more logical and reliable. But the php function for "the_ID" starts within the loop and the session_start begins before any headers or functions.
How do I get the value of "the_ID" in the session_start from that same post page so it can be used in the pages that follow? (The id changes for each new post)
Is this the most efficient way to handle this?
Is there any problem with the way I did it?
My php info:
PHP Version: 5.1.6
Display Errors: On
Error Level: Not E_ALL
Register Globals: On
Thank you for helping. I hope someday I'll be able to give back.