Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Passing user specific data from form to form View modes: 
User avatar
Member
Member
RoyR - 3/29/2012 3:11:24 PM
   
Passing user specific data from form to form
Hello,

I am new to Kentico, and was wondering if somebody could help point me in the right direction.

I have a set of three forms that are set up in a hierarchy, and I would like to pass some information from form to form. In the first form the user enters some data. To make it simple I will just say it is their name and DOB. Also, I am generating a GUID for the user in the first form. Here is the code to generate the GUID (“ID” is the name of the GUID form element):

//Generate GUID
//.ascx markup
OnOnBeforeSave="viewBiz_SetGUID"
//code behind
protected void viewBiz_SetGUID(){
string GUID = Guid.NewGuid().ToString();
if (this.viewBiz.BasicForm.FieldControls.ContainsKey("ID")){
this.viewBiz.BasicForm.DataRow["ID"] = GUID;
}
}


Once the 1st form is submitted, a link to the 2nd form will be sent to another party’s email. This link will contain a query string with the user’s GUID.

The name and DOB of the user have to be passed to the 2nd form to be viewed by the other party, who also need to enter some new info. I would like to use the GUID in the query string to identify the record with which to populate the “Name” and “DOB” fields of the second form. Here is the code for pulling the query string from the URL:

public override void OnContentLoaded(){
base.OnContentLoaded();
SetupControl();
Control ctrl = Form2.BasicForm.FindControl("ID");
if ((ctrl != null) && (ctrl is TextBox)){
if ((Request.QueryString["GUID"] != null) && (Request.QueryString["GUID"] != "")){
((ID)ctrl).Text = Request.QueryString["GUID"];
}
}
}


Also, here is my current (incomplete) code for pulling the user’s name and DOB data from the first form into the second form:

CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider();

Control nameCtrl = Form2.BasicForm.FindControl("Name");
CMS.TreeEngine.TreeNode nameNode = tree.SelectSingleNode(Name).Parent;
((Name)nameCtrl).Text = nameNode.GetValue("Name");

Control dobCtrl = Form2.BasicForm.FindControl("DOB");
CMS.TreeEngine.TreeNode dobNode = tree.SelectSingleNode(DOB).Parent;
((DOB)dobCtrl).Text = dobNode.GetValue("DOB");


My problem is that I can’t find a way to specify which record to pull this data from; I would need to search through all the records from the 1st form to find a GUID that matched the query string, and say pull the information from that record. Is there a way that I can do this?

Any other comments or tips are welcome as well

Thanks

User avatar
Member
Member
kentico_michal - 4/2/2012 4:03:53 AM
   
RE:Passing user specific data from form to form
Hello,

You can use the following method to get a record saved by the first form. You just need to specify a where condition with the guid retrieved from the Url so that only one appropriate record is returned:

DataSet ds = BizFormItemProvider.GetItems(string className, string where, string orderBy)

Best regards,
Michal Legen

User avatar
Member
Member
RoyR - 4/3/2012 8:28:18 AM
   
RE:Passing user specific data from form to form
perfect, thanks!