Forum Moderators: coopster

Message Too Old, No Replies

losing post variables when parsing

         

Robert Poole

12:21 pm on Jun 7, 2007 (gmt 0)

10+ Year Member



Hey guys. I'm new here; I just signed up because I'm getting my ass kicked by something that really shouldn't be kicking my ass. I found out about this board by googling this thread:

[webmasterworld.com...]

Unfortunately it is too late to reply to though :o(

Anyway, here's my problem...

I have a form which reads in a date that the user selects
This is then processed on a page which generates an xml file with an automatically generated filename which includes the user ID.
This is then passed onto a calendar page, which uses the previous two pages to populate the calendar with the generated xml file. The calendar displays the current month, with the option to navigate to other months using links like <a href=\"?year=$prevYear&monthNo=$prevMonth\"> and a href=\"?year=$nextYear&monthNo=$nextMonth\">.

The problem is when you want to change the month you are viewing on the calendar the user ID is lost as it was originally posted to the page from a form, so I need a way to store this variable while users navigate throughout the months in the calendar.

I've had a crack at cookies, sessions and turning the links into forms with hidden fields but I can't get anything to work. Any help would be greatly appreciated.

Rob

Habtom

1:03 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> I've had a crack at cookies, sessions and turning the links into forms

What seems left is storing the value in a database.

Hab

// or txt file for that matter.

[edited by: Habtom at 1:11 pm (utc) on June 7, 2007]

Robert Poole

1:19 pm on Jun 7, 2007 (gmt 0)

10+ Year Member



This is an option, and I could do this for my registered users, but I really need to generate the calendar for guests as well, so I really just need a way of reading the post variable into a cookie, but in such a way that this variable can be maintained as the user browses from month to month.

Thanks for the suggestion though. Definately something to have a think about.

Habtom

1:34 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> the user ID is lost as it was originally posted to the page from a form

Storing the value in a session, do you lose the value? Why? Can you post the code in question.

Hab

Robert Poole

2:13 pm on Jun 7, 2007 (gmt 0)

10+ Year Member



Sure. Here is the second page where the XML file is generated, it concludes with

----------------------------------------------------
$ourFileName = "users/user".$numfiles.".xml";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $finalpackage);
fclose($ourFileHandle);
echo "The XML file (ID: ".$numfiles.") has been created.";

?>

<form name="GoToCalendar" action="calendar/calendar.php" method="post" id="GoToCalendar">
<input type="hidden" name="userid" id="userid" value="<?php echo $numfiles;?>" />
<input type="submit" style="width:0px;height:0px" value="">
</form>
----------------------------------------------------

This is then automatically submitted to the next page (the calendar page), then on my calendar page I have something like

----------------------------------------------------
setcookie("chocchip", $_POST['userid']);
echo $_COOKIE["chocchip"];

// name of XML file which contains your event data
$xmlFile = "../users/user".$_COOKIE["chocchip"].".xml";

// name of header file
$headerFile = "header.inc";

// name of footer file
$footerFile = "footer.inc";
----------------------------------------------------

And this will work fine until the viewer changes month

----------------------------------------------------
// print links for previous and next months
echo "<p align=\"center\">[ <a href=\"?year=$prevYear&monthNo=$prevMonth\"><< $prevMonthName</a> ¦ <a href=\"?year=$nextYear&monthNo=$nextMonth\">$nextMonthName >></a> ]</p>\n";
----------------------------------------------------

I don't know if that made my problem any clearer?

coopster

11:19 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Robert_Poole.

When changing months you are using a GET request (<a href="http://www.example.com/mypage.php?name=value") which passes variables via the query string. The query string in a GET request is the "stuff" that comes after the question mark in a URI.

Since the userID is not being passed, you won't have it on the next page. You'll have to retrieve the COOKIE value to get it so you can use it.

Robert Poole

8:30 am on Jun 8, 2007 (gmt 0)

10+ Year Member



Good look Coopster.

I put an if statement in the top of my calendar page like

if (!isset($_GET['userid']))
{
$userid = $_POST['userid'];
}
else
{
$userid = $_GET['userid'];
}

and then hard coded the user ID in the change month tags like
<a href=\"?year=$nextYear&monthNo=$nextMonth&userid=$userid\">

and that seems to have fixed this problem, so thanks for your help!

Now all I have to do is figure out why I can't generate any events for the 1st of any month! The fun of programming knows no boundaries!

Anyway, thanks for your help again, I will probably be back in the forums shortly with another PHP related question!