Multi-functional submit button on Alternative Form

Noud de Rover asked on September 15, 2018 18:47

We have an alternative form with a submit button and we would like to make this button multi-functional. It should be able to: - Save the form data - Add a product to the shopping cart (if not yet added) - Redirect to the shopping cart.

Is this possible and how to achieve this?

Thanks for your help.

Recent Answers


David te Kloese answered on September 17, 2018 10:08 (last edited on September 17, 2018 16:11)

So if you don't have yet you can create a custom Web Part (or widget) on which code before you have a basic form:

<cms:BasicForm ID="yourNiceForm" runat="server" IsLiveSite="true" />

which you populate with the Alternative form that is selected in the Web Part properties?

Somewhat like:

AlternativeFormInfo afi = AlternativeFormInfoProvider.GetAlternativeFormInfo("YourCustomFormName");
if (afi != null)
{
    yourNiceForm.Data = new TheObjectYouWantToFill(); //can be a custom class

    yourNiceForm.FormInformation = FormHelper.GetFormInfo("YourCustomFormName", true);
    yourNiceForm.AltFormInformation = afi;
    yourNiceForm.Visible = true;
    yourNiceForm.IsLiveSite = true;

    yourNiceForm.OnAfterSave += yourNiceForm_OnAfterSave;

    ... and so on

}

Than you can add the following method

private void yourNiceForm_OnAfterSave(object sender, EventArgs e)
{
    // create TheObjectYouWantToFillInfo object from form data
    TheObjectYouWantToFillInfo item = (TheObjectYouWantToFillInfo) yourNiceForm.Data;

    if (item != null)
    {
        //extend object with 
        item.YourSecretDateField = DateTime.Now;

        // your custom logic...
    }
}

You can take the 'CustomRegistrationForm' Web Part (or any other using a Alternative Form) as an example: You can find the code at: ~/CMSWebParts/Membership/Registration/CustomRegistrationForm.ascx.cs

Depending on the exact requirements this should get you started.

1 votesVote for this answer Mark as a Correct answer

Noud de Rover answered on September 18, 2018 18:27 (last edited on September 18, 2018 23:57)

Hi David,

Thank you so much for your help!

Noud

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on September 19, 2018 14:39

@Noud - I've seen your initial reply and LI message, but didn't had time to respond yet. Can't seem to find it again so assume you've found an alternative!

Let me know if you have more questions.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.