Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jan Brinker 77 posts 103 karma points
    May 03, 2013 @ 17:34
    Jan Brinker
    0

    Rendering a Form without setting cookies

    Hiho,

    is there a way of letting a form render without setting cookies for auto-resume?

    I've got the following problem: My project (custom workflow) is a modified version of the ScoreCalculator (http://www.nibble.be/?p=83), which calculates a sum and then redirects the user to a page on a different server (payment gateway. Now If the user signs up once, everything works as it should. However if he returns to the form and fills it out again (specific case: seminar registration form and the user wants to enter several participants), the existing record in the database is overwritten, since the cookie tells the system to resume the form. Now there are two incoming payments but only one entry in the database (bad).

    By googleing I found some code to delete the existing cookie. I tried invalidating/expiring the cookie inside the Workflow like this:

    if (HttpContext.Current.Request.Cookies["contour_" + record.UmbracoPageId + "_" + args.Form.Id] != null)
    {
    var contourCookie = HttpContext.Current.Request.Cookies["contour_" + record.UmbracoPageId + "_" + args.Form.Id];
    contourCookie.Expires = DateTime.Now.AddDays(-1d);
    HttpContext.Current.Request.Cookies.Add(contourCookie);
    queryString = args.Form.Id.ToString();
    }
    HttpContext.Current.Response.Redirect("https://paymentgatewayredirect.here")

    This has no effect at all. So I tried creating my own macro for rendering the Form by basically copying the standard Razor-Code for rendering the form and adding the cookie-invalidation:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @using Umbraco.Forms.Mvc.Bridge.Html;
    @{
    string action = "ContourForm";
    string controller = "FormRender";
    string formtoken = "UmbracoContourForm";
    string formGuid = Parameter.FormGuid;

    @* First get rid of the cookie storing old form values. This is desireable in some signup-forms. *@
    if (!IsPost)
    {
    if (Request.Cookies["contour_"+Model.Id+"_" +formGuid] != null)
    {
    var contourCookie = Request.Cookies["contour_"+Model.Id+"_" +formGuid];
    contourCookie.Expires = DateTime.Now.AddDays(-1d);
    Response.Cookies.Add(contourCookie);

    Response.Redirect(Request.Url.ToString());
    }
    }

    @Html.RenderMvcAction(action, controller, formGuid, formtoken, (umbraco.MacroEngines.DynamicNode)Model, (System.Dynamic.DynamicObject)Parameter);
    }

    This causes the system to create new records in the database, when a user comes back and signs in a second time. However it has the undesired side-effect of somehow destroying the data I receive in the Workflow. The values themselves are correctly stored in the database (I can see all the entered data in the backend and each time another entry is created) but the calculation fails and the returned score (/price) is 0.

    Now I ask myself, shouldn't there be the possibility to directly deactivate the setting of a cookie? Seems to me that this would be a somewhat cleaner approach than alwazs setting it and directly invalidating it (and getting a bad side effect.)

    Or any other suggestions how to handle my problem?

  • Jan Brinker 77 posts 103 karma points
    May 07, 2013 @ 10:41
    Jan Brinker
    0

    Not even a way to lock a Record, so it never gets overwritten?

  • Comment author was deleted

    May 07, 2013 @ 15:06

    Hmm sure you are using the razor macro to output the form, that one shouldn't even use the cookie

  • Jan Brinker 77 posts 103 karma points
    May 07, 2013 @ 15:53
    Jan Brinker
    0

    That explains only one thing I've been wondering about. OK, yes there is no cookie set when I use the Razor macro.

    That still leaves me with the previous problem, so apparently I didn't hit mark with the topic of this thread. My calculator workflow keeps on spitting out a 0 as a sum, no matter what I do. In the backend I can see the values though, so they must reach the database somehow, just not my workflow. I tried debugging, which is a pain since it seems I can't log anything and I can't send myself any emails from this workflow (don't ask me why), even if I use the sourcecode of the email-workflow and copy-paste it. The workflow just crashes and stops being executed. So I am currently clueless on how to proceed.

    I receive all the values for processing without problem when using the Usercontol macro. However this one in turn has the problem of auto-resuming forms, what is undesireable in my case. Also I'm not sure, if just rooting for the Razor macro and trying to find a solution in the code is a good idea, as with coming releases of Contour the cookies will be enabled and bam I will have the same problem I'm having right now with the Usercontrols. So the best way for me seems to find out now how to disable auto-resume in general.

    Any thoughts?

  • Comment author was deleted

    May 07, 2013 @ 17:58

    It's due to a change in Contour, the calc method needs to be updated, I can provide a snippet tomorrow

  • Comment author was deleted

    May 08, 2013 @ 09:49

    Here is the updated snippet

     

       foreach (RecordField rf in record.RecordFields.Values)

                {

                    if (rf.Field.FieldType.GetType() == typeof (Umbraco.Forms.Core.Providers.FieldTypes.RadioButtonList))

                    {

                        if (rf.Values.Count > 0)

                        {

                            var pvkey = pvs.GetAllPreValues(rf.Field).First(p => p.Value == rf.Values[0].ToString()).Id;

     

                            if (scores.ContainsKey(pvkey.ToString()))

                                score += scores[pvkey.ToString()];

                        }

                    }

  • Jan Brinker 77 posts 103 karma points
    May 08, 2013 @ 13:20
    Jan Brinker
    0

    Great, thanks a bunch! That seems to work now.

    But what should I do when in a future version the razor macro actually sets cookies?

    Another question I have now is, did something in the mail-workflow change, too? I didn't really look into it, but I somehow can't send emails anymore from my workflow.

    Not even like this:

    System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
    m.From = new System.Net.Mail.MailAddress(umbraco.UmbracoSettings.NotificationEmailSender);
    m.Subject = "test";
    m.IsBodyHtml = true;

    m.To.Add("[email protected]");
    m.Body = "<p>booyaa</p>";

    System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient();
    s.Send(m);

    Thanks for the help!

  • Comment author was deleted

    May 08, 2013 @ 13:22

    Nope nothing changed in the mail workflow make sure you have an smtp server setyp and that the umbraco.UmbracoSettings.NotificationEmailSende is a valid email address

  • Jan Brinker 77 posts 103 karma points
    May 08, 2013 @ 14:28
    Jan Brinker
    0

    Ok, I'll check this.

    However we have a slight setback to the initial problem. The customer who runs the Umbraco installation which should receive the new workflow is a 4.7.11 and it won't swallow the Razor script. (Could not find namespace Mvc)

    The only way for us is to render the macro via Usercontrols..

  • Comment author was deleted

    May 13, 2013 @ 09:53

    You should be able to just add the mvc assembly to make it work

  • Jan Brinker 77 posts 103 karma points
    May 13, 2013 @ 11:33
    Jan Brinker
    0

    You mean I should copy over the Umbraco.Forms.Mvc.dll ?

    We tried that and it crashed the system. Wasn't able to render any XSLT files anymore. The system crashed immediatly when trying to execute, save or create an XSLT file.

  • Comment author was deleted

    May 14, 2013 @ 10:36

    Any details on the error?

  • Jan Brinker 77 posts 103 karma points
    May 15, 2013 @ 13:36
    Jan Brinker
    0

    I can't put the dll into the live server again, too risky. So I tried making a copy of the folder structure and the database, but somehow the frontend won't render. So the only detailed error I can give you is the one I get when the Umbraco.Forms.Mvc.dll is in the bin folder and I try to create an XSLT file:

     

    Server Error in '/' Application.


    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       umbraco.macro.GetXsltExtensionsImpl() +942
       umbraco.macro.<GetXsltExtensions>b__6() +5
       umbraco.cms.businesslogic.cache.Cache.GetCacheItem(String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) +132
       umbraco.macro.GetXsltExtensions() +205
       umbraco.macro.AddXsltExtensionsToHeader(String xslt) +131
       umbraco.XsltTasks.Save() +410
       umbraco.presentation.create.dialogHandler_temp.Create(String NodeType, Int32 TypeId, Int32 NodeId, String Text) +385
       umbraco.presentation.create.xslt.sbmt_Click(Object sender, EventArgs e) +173
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
    



    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

    ____

    the day before yesterday, when I copied the dll into the live server I only received "Error parsing XSLT" messages on the frontend wherever an XSLT-macro should have been rendered.

Please Sign in or register to post replies

Write your reply to:

Draft