Populating form fields with Sessions..

Ron 29 Feb, 2012
Hello,

I am trying to populate similar form fields with data filled by the user on an earlier form so when the user is directed to a next form he does not find an empty form but what fields he filled earlier are already pre-filled. Here is the code that would go at the top of the page:

session_start();
$_SESSION['region'] = $region; //use $_POST[''] or whatever to collect this information from form
$_SESSION['country'] = $country;
$_SESSION['city_state'] = $city_state;
$_SESSION['fullname'] = $fullname;
$_SESSION['address1'] = $address1;
$_SESSION['address2'] = $address2;
$_SESSION['city'] = $city;
$_SESSION['zip'] = $zip;
$_SESSION['email'] = $email;
$_SESSION['phone'] = $phone;



if(isset($_POST['save']))
{
if ($_POST['valid']=="true")
{
$region = $pageForm.region.value;
$country = $_POST['country'];
$_SESSION['city_state'] = $_POST['city_state'];
$fullname = $_POST['fullname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$phone = $_POST['phone'];

if(!get_magic_quotes_gpc())
{

// if there are not slashes around the variable data, put them around the infomation to enable it to be entered into
// the database correctly
$region = addslashes($_POST['region']);
$country = addslashes($_POST['country']);
$city_state = addslashes($_POST['city_state']);
$fullname = addslashes($_POST['fullname']);
$address1 = addslashes($_POST['address1']);
$address2 = addslashes($_POST['address2']);
$city = addslashes($_POST['city']);
$zip = addslashes($_POST['zip']);
$email = addslashes($_POST['email']);
$phone = addslashes($_POST['phone']);


print_r($_SESSION);
}
}
}

I am not able to get it to work. Has anyone at the forum worked with sessions. i would appreciate suggestions.

Thanks in advance.

Ron
GreyHead 29 Feb, 2012
Hi Ron,

I CnronoForms v3 the Multi-page plug-in uses sessions to pass the data between pages; in CFv4 there are 'Data to Session' and 'Session to Data' actions that you can use. Joomla! also has session methods that are easy to use in PHP.

Bob
Ron 29 Feb, 2012
Thanks for the answer bob.

I tried the Data to session and session to data but seems to not work for me. Maye be I have made a mistake some where, but most of my forms are custom hope that is not the reason it not working for me.

I am going to have a look again. Your views are highly appreciated.

UPDATE 10 minutes later:The Data to session and session to data does not work for me. I do not know where I may be going wrong.

thanks a lot

Ron
GreyHead 29 Feb, 2012
Hi Ron,

Make sure that you use the same Session Key on both actions. It defaults to the form name and that will be different.

Bob
Ron 01 Mar, 2012
Hello Bob,

I get the following error when I debug the system:

Array
(
[option] => com_chronoforms
[chronoform] => testing
[Itemid] =>
)


Any Suggestions

Thanks
Ron
GreyHead 01 Mar, 2012
Hi Ron,

Is the debugger at the end of the ON Load action?

If so then your Session Data is either not being saved or not being recovered.

Bob
Ron 01 Mar, 2012
Bob,

I put the debugger at the end at the beginning in the middle in the on submit but no change. The form does not display either only the debug code is visible.

Is the debugger at the end of the ON Load action?
If so then your Session Data is either not being saved or not being recovered.



Thanks

Ron
GreyHead 01 Mar, 2012
Hi Ron,

Then check the session action settings please.

Bob
Ron 01 Mar, 2012
Hello Bob,

Sorry.. But I did not find where is session action settings.๐Ÿคจ Please advise.

Thanks
Ron
GreyHead 02 Mar, 2012
Hi Ron,

Sorry, I meant the settings for the 'Data to Session' and 'Session to Data' actions.

Bob
Ron 02 Mar, 2012
Bob !
Where are these settings ? I am sorry there is no setting for data to sessions and sessions to data actions. Maybe I am over looking these.
As suggested I did accordingly: But I can't see it anywhere..

To install this action unzip the file and copy the files to the administrator/components/com_chronoforms/form_actions/load_user_info_gh folder on your site.



Please help
Ron
GreyHead 03 Mar, 2012
Hi Ron,

Yes there are; and, as I said earlier, you must set the same Session Key in both actions.

Bob
Ron 04 Mar, 2012
Bob..

Thanks for the reply. This is something that I did much earlier. I was thinking there are more setting apart from this ๐Ÿ™‚ and on both the forms I have same settings
GreyHead 04 Mar, 2012
Hi Ron,

In that case it should all work OK. I don't know why it doesn't. Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
This topic is locked and no more replies can be posted.