This topic is locked

form data from webpage

11/23/2009 9:10:36 AM
PHPRunner General questions
F
fpilot author

I want the members to click on a link to add the item in a wishlist [table] but in case they are not logged in I want the user to be taken to login page or if he/she is logged in then the data to be filled in the add page form from the link thru get method. Pls advise.

J
Jane 11/24/2009

Hi,
please post example of your link here.

F
fpilot author 11/24/2009



Hi,
please post example of your link here.


This is a page which is outside the members area: http://ecommi.com/jamat/donationpublic/menu/indexdonation.php?centerpage=home.php&CatId=327&Type=Product#addtolist.php

I want the user to be able to add the item in the wishlist table which is in the members area portal at: http://ecommi.com/jamat/donationusers/login.php after the user has logged in.
Now How I should receive the data in the secure area which requires password, so that even if the login page is in the middle the data gets added into the table or wishlist form gets filled out.
I am not sure if you'll be able to make sense out of this. Need help I am stuck at this point.

J
jsuisman 11/25/2009



This is a page which is outside the members area: http://ecommi.com/jamat/donationpublic/menu/indexdonation.php?centerpage=home.php&CatId=327&Type=Product#addtolist.php

I want the user to be able to add the item in the wishlist table which is in the members area portal at: http://ecommi.com/jamat/donationusers/login.php after the user has logged in.
Now How I should receive the data in the secure area which requires password, so that even if the login page is in the middle the data gets added into the table or wishlist form gets filled out.
I am not sure if you'll be able to make sense out of this. Need help I am stuck at this point.


Hey fpilot,
It sounds to me like you'd want to use a php session variable to make this work. That way you could keep everything in the user's wishlist whether they're logged in or not.
To set up the session variable you would use:



$_SESSION['wishlist'] = Array();


The code to add an item to the array is:



$_SESSION['wishlist'][] = "itemNumber1";


Now $_SESSION['wishlist'][0] will be itemNumber1. Use $_SESSION['wishlist'][] = "something"; every time you want to add another item to the array.
Then after the user logged in to the members screen, you can access this session variable in an event. The following code will loop through all the items in the wishlist session variable:



for ($i=0;$i<sizeof($_SESSION['wishlist']);$i++)

{

//Do something here with $_SESSION['wishlist'][$i]

}


Also, after you're done, you should unset the session variable with:



unset($_SESSION['wishlist']);


Good Luck,
Jarred

F
fpilot author 11/26/2009

Thx a bunch! will try that.



Hey fpilot,
It sounds to me like you'd want to use a php session variable to make this work. That way you could keep everything in the user's wishlist whether they're logged in or not.
To set up the session variable you would use:



$_SESSION['wishlist'] = Array();


The code to add an item to the array is:



$_SESSION['wishlist'][] = "itemNumber1";


Now $_SESSION['wishlist'][0] will be itemNumber1. Use $_SESSION['wishlist'][] = "something"; every time you want to add another item to the array.
Then after the user logged in to the members screen, you can access this session variable in an event. The following code will loop through all the items in the wishlist session variable:



for ($i=0;$i<sizeof($_SESSION['wishlist']);$i++)

{

//Do something here with $_SESSION['wishlist'][$i]

}


Also, after you're done, you should unset the session variable with:



unset($_SESSION['wishlist']);


Good Luck,
Jarred

F
fpilot author 11/27/2009

I tried the code but when the link takes the user to the login page after the session has been set the session gets lost and nothing is passed on.
May be the login page unsets all the sessions.



Thx a bunch! will try that.

J
jsuisman 11/27/2009

Yah must be. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=45767&image=1&table=forumreplies' class='bbcemoticon' alt='<<' />
You'd have to use a cookie then.
Here is the link to set cookie page on php.net. There is also a simple example of how to retrieve cookies.
http://php.net/manual/en/function.setcookie.php
The easiest way would be every time a user clicks adds another item to his wishlist, you'd concatenate a separator and the item number onto the cookie variable. Then when you wanted to parse the variable in a phprunner custom event, you explode on that separator into an array of item numbers. I'd avoid using an array of cookies because you'd need a persistent counter and it adds another layer of complexity and I'm not sure how strong your php skills are. Here is a real quick example:
Yuo may want to put these two functions in a php page outside of phprunner and just do an include_once("thatpage.php") in the header of your phprunner project.



/*

* Call this function whenever a user adds an item to wishlist

*/

function AddItem($itemNumber){

if (!isset($_COOKIE['wishList'])) { //if there is no wishlist yet, create cookie

setcookie("wishList", $itemNumber, time()+3600); /* create cookie -- it will expire in 1 hour or 3600 seconds, can change the +3600 as needed */

}else{ //cookie already exists

$_COOKIE["wishList"] .= ",".$itemNumber; //concatenate comma plus new item number

}

}

/*

* Call this function to get wishlist as an array

*/

function GetWishlist(){

if (isset($_COOKIE['wishList'])) { //make sure the wishlist is set

$wishListArr = explode(",",$_COOKIE['wishList']); //create an array containing all items, split on commas

return $wishListArr;

}else{

//no wishlist, return something else like null or false

}

}


Once you have the array, you could loop through it in a phprunner event like I posted in my previous post.
This is a very simple example, you could implement this many different ways. I also didn't put any checks in for bad data and the like.
Good luck,
Jarred