[thelist] CF: Moving a struct to a session.var
.jeff
jeff at members.evolt.org
Wed Aug 14 21:14:01 CDT 2002
frank,
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Frank
>
> Help! I'm stuck. I'm playing around with structs. The
> user has completed a form with some basic information.
> I want to set it to a struct in the session scope that
> I can move from page to page without losing the data.
>
> The code below (formatted this way just to deal with
> wrapping) is an example of what I'm using. I keep
> getting the "can't resolve parameter" error. All my
> other session variables carry through.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
your friend is the Duplicate() function and square brackets.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> (Tangent: How *does* one output in a cfscript?)
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
with the writeOutput() function.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> StructInsert(ContactDetails
> ,"EmailAddress"
> ,"#Form.EmailAddress#");
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
first, don't mix double-quotes and hashes. drop both and you'll be just fine.
StructInsert(ContactDetails
, 'EmailAddress'
, Form.EmailAddress);
or, using dot notation:
ContactDetails.EmailAddress = Form.EmailAddress;
or, using bracket notation:
ContactDetails['EmailAddress'] = Form.EmailAddress;
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> // Copy this struct to a session variable
> Session.ContactDetails=StructNew();
>
> Session.ContactDetails=StructCopy(ContactDetails);
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
use the Duplicate() function instead since the StructCopy() function creates a reference to the local copy instead of creating a new copy.
Session.ContactDetails = Duplicate(ContactDetails);
this is a bunch of extra work though that's not really necessary unless you only want to save a portion of the form elements. if you really do want to save the entire form that was posted, then just use the Duplicate() function to make a copy in the session scope.
Session.ContactDetails = Duplicate(Form);
good luck,
.jeff
http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/
More information about the thelist
mailing list