Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Returning Wrong Form View modes: 
User avatar
Member
Member
Skip - 1/9/2012 4:16:17 PM
   
Returning Wrong Form
I am creating a customized registration webpart that will use alternative forms. The web part is pulling the alternative form id from the event record. The problem that I have run into is that web part is reloading the base form if the validation fails. Can anyone give me a clue where to look. I have walked through the code in debug and do not see where it is initiating this load.

I apologize if this has already been discussed. I am new to Kentico and I find searching Kentico's site difficult. (Part of that could be caused by my inability to figure out the correct terms to enter in the search)

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/10/2012 3:15:06 AM
   
RE:Returning Wrong Form
Hello,

Are you using any custom code to do this? I am not aware of any issues in previous versions regarding this, but if the validation fails, the alternative form should be used as normally, only with an error message. Could you please post your custom code, if you are using any? Additionally, which version of Kentico are you using, including hotfix?

Best regards,
Boris Pocatko

User avatar
Member
Member
Skip - 1/10/2012 7:52:44 AM
   
RE:Returning Wrong Form
I have written custom code and I am sure that is where the problem is at. I am back to programming in .net after a 10 year break writing Coldfusion code.

I have created a new document type for the calendar events. The document type holds the alternative form id.

Here is the code.

private void SetupControl()
{
if (this.StopProcessing)
{
//Do nothing
}
else
{
if (!IsPostBack)
{
EventNode = CMSContext.CurrentDocument;
RegForm = 0;

//Get form ID from the event record.
RegForm = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(EventNode.DataRow, "EventRegistrationFormID"), 0);
if (RegForm > 0)
{
var AltForm = AlternativeFormInfoProvider.GetAlternativeFormInfo(RegForm);

if (AltForm != null)
{
customTableForm.CustomTableId = AltForm.FormClassID;
customTableForm.AlternativeFormFullName = AltForm.FullName;
this.hdAltForm.Value = AltForm.FullName;
customTableForm.SiteName = SiteName;
customTableForm.UseColonBehindLabel = UseColonBehindLabel;
customTableForm.ItemID = 0;

customTableForm.ShowPrivateFields = true;
customTableForm.OnAfterSave += customTableForm_OnAfterSave;
customTableForm.OnAfterValidate += customTableForm_OnAfterValidate;
customTableForm.BasicForm.SubmitButton.Visible = false;
}
if (ValidationHelper.GetBoolean(CMSContext.CurrentDocument.GetValue("EventPayRequired"), true))
{
uxCreditCardProcess.Visible = true;
}
}
else
{
Views.SetActiveView(NoReg);
}
}
}
}

protected void customTableForm_OnAfterValidate()
{
if (CreditCardInformationRequired)
{
// Call the validation on the credit card form
// Invalid credit card information, stop processing
// Add validation message if handled here and not on the credit card form
if (!uxCreditCardProcess.CCValidate())
{
customTableForm.StopProcessing = false;
}
}
}

private void customTableForm_OnBeforeSave()
{
}

private void customTableForm_OnAfterSave()
{
lblInfo.Text = ResHelper.GetString("general.changessaved");
lblInfo.Visible = true;
customTableForm.Visible = false;

// Before saving Custom Table data, submit the credit card information (if needed) for authorization
if (ValidationHelper.GetBoolean(CMSContext.CurrentDocument.GetValue("EventPayRequired"), true))
{
// The credit card would have been validated on submit of the page
// Take their money!
var vGlNumber = CMSContext.CurrentDocument.GetValue("GLNumber");

// TODO: Change call to pass parameters
if (uxCreditCardProcess.Submit2Gateway())
{
// TODO: Save the authorization code

Views.SetActiveView(Success);
}
else
{
// Submission failed, stop the Custom Table Form
customTableForm.StopProcessing = true;
}
}

// EditingFormControl fc = (EditingFormControl)customTableForm.BasicForm.FieldEditingControls["AuthCode"];
// fc.Value = uxCreditCardProcess.AuthorizationCode;
var x = customTableForm.BasicForm.EditedObject as CMS.DataEngine.SimpleDataClass;
if (x != null)
{
var p = new CustomTableItemProvider(UserInfoProvider.GetFullUserInfo(53));
var item = p.GetItem((int)x.DataRow[0], "deac_Reg_CustomTable.BigBroSis");
item.SetValue("AuthCode", uxCreditCardProcess.AuthorizationCode);
item.SetValue("CardNumber", uxCreditCardProcess.Last4CardNo);
item.Update();
}
}
protected void btnRegister_Click(object sender, EventArgs e)
{
customTableForm.AlternativeFormFullName = hdAltForm.Value;
bool bsave = customTableForm.BasicForm.SaveData("");
}

User avatar
Member
Member
Skip - 1/11/2012 1:00:08 PM
   
RE:Returning Wrong Form
I forgot to give you the rest of the information. We are on 5.5R2. I think we are update on any hotfixes.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/12/2012 5:40:32 AM
   
RE:Returning Wrong Form
Hello,

Thank you for the details, however I will need to know a bit more to set up the same scenario on my side to debug the issue. Could you please describe your setup? I assume, according to the description above, your current setup is something like this:

1) You have an CMS.Event (Event booking system?) document type with an added custom field "EventRegistrationFormID" where the ID of the alternative form is saved.

2) You've created a new web part which is placed on a Event document type in the CMSDesk, which has a form on it.

Regrettably, the code you've posted isn't complete and there are missing some variables which I am not sure, if are relevant to the issue (hdAltForm, uxCreditCardProcess ...). Could you please post the whole web part somewhere where I can download it and import it to my site so I can test it? It would be great if you would include your setup so I can fully test it and please try to strip the code from unnecessary lines, if it's possible.

Best regards,
Boris Pocatko

User avatar
Member
Member
Skip - 1/13/2012 8:32:18 AM
   
RE:Returning Wrong Form
Can I send it to the support email address? I do not want to post all of the code since it includes credit card processing.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/15/2012 3:42:01 AM
   
RE:Returning Wrong Form
Hello,

Yes, of course. Please send the files in such form, in which I can test it with minimal modification. Please also include instructions, how to get it running if possible. Thank you in advance!

Best regards,
Boris Pocatko

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 1/27/2012 1:44:55 PM
   
RE:Returning Wrong Form
Hi,

Just so that other visitors of this forum thread would know the correct answer to this issue, Alternative form needs to be setup in OnContentLoaded method. Example:

public override void OnContentLoaded()
{
base.OnContentLoaded();
customTableForm.AlternativeFormFullName = "customtable.SampleTable.test";
}


This is not a problem of ViewState but just issue with life cycle of this control. By issue I don’t really mean that there is any problem with this control, it is just how the control internally works.

Thanks,
Miro