Copied to clipboard

Flag this post as spam?

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


  • Lilian Hughes 11 posts 31 karma points
    Mar 11, 2011 @ 12:06
    Lilian Hughes
    0

    Store Cookie on Submit

    Please bear with me, I'm a newbie at this Umbraco malarkey. However, I am losing the will to live.

    I've inherited a previously developed Umbraco system and have been quite happy doing changes in the CMS with xslt & macros and the like.

    Our client has requested the following:

    1. Provide a list of PDF documents to download (dead simple)
    2. A form to capture a name, email & company (again dead simple - contour)
    3. The ability to stop users from downloading the documents until the form has been filled in - I'm thinking cookie.

    What I want to be able to do is this.

    User clicks on link to the downloads section.
    Check to see if the cookie exists
    If cookie exists and is valid then send user to the download section
    If cookie does not exist/invalid send user to contour form
    Once completed set the cookie and redirect to downloads section
    If someone tries to go directly and the cookie is missing/invalid then we redirect to the download section.

    Why can't I set a cookie in the Submit workflow?

    Thanks

     

    Disgruntled David

  • Tom Maton 387 posts 660 karma points
    Mar 11, 2011 @ 12:49
    Tom Maton
    0

    Hi David,

    You could set the cookie using jQuery on the submission of the form.

    http://www.electrictoolbox.com/jquery-cookies/

    Thanks

    Tom

  • Lilian Hughes 11 posts 31 karma points
    Mar 15, 2011 @ 11:24
    Lilian Hughes
    0

    Apologies for the delay. I thought I'd written a response.

    The .submit of jQuery doesn't seem to be called when the form submits. I have a feeling that contour already add javascript to the submit event which is causing the jQuery to fail??

    (I've created a template called "SubmitForm" that loads the jQuery from MS)

    I've tried all sorts of combinations of form name to try and get this damn thing to work:

    <script>
        $("form").submit(function() {
    alert("test");
    $.cookie("bondholderform", "1", { expires: 7 });
    return false;
          }
    </script>

     

    I've tried "aspnetForm" etc etc.

    Am I being thick?

    Thanks

    David

  • Tom Maton 387 posts 660 karma points
    Mar 15, 2011 @ 12:01
    Tom Maton
    0

    Hi David,

    Try doing it on the click of the button instead of the submit (not tested fully)

    <script>
    $(document).ready(function () {
        $("#form").live('click',function() {
            $.cookie("bondholderform", "1", { expires: 7 });
         
    });
    });
    </script>

    This should allow the adding of the cookie and then the submission of the form as the return false will stop this.

    Hope this helps

    Tom

  • Lilian Hughes 11 posts 31 karma points
    Mar 22, 2011 @ 15:12
    Lilian Hughes
    0

    Hi Tom,

    Sorry for the delay.

    I tried your suggestion but it seems as though that code executes as soon as you click anything in the form - so I don't even have chance to fill in the textboxes.

    The form submit button is rendered by the asp.net engine and gets called something silly "ctl001ctl001ctl001..." etc.

    Am I the only person that has this need?

    Thanks again, David

    PS. I added "return false" just as a test to see if that helped my cause

  • Lilian Hughes 11 posts 31 karma points
    Mar 22, 2011 @ 15:21
    Lilian Hughes
    0

    Hi Tom,

    You set me on the right track!! This seems to do the trick....

    <script>
    $
    (document).ready(function () {
        $(".contourSubmit").live('click',function() {
            $.cookie("bondholderform", "1", { expires: 7 });
         
    });
    });
    </script>
  • Comment author was deleted

    Mar 22, 2011 @ 15:27

    Hi David,

    You can also use the Contour event model to set a cookie on submit (trough c# code not jquery).

    There is an example here: http://www.nibble.be/?p=81  (step 3)

     

    using System;
    using Umbraco.Forms.Core.Services;

    namespace Contour.Addons.ScoreCalclulator
    {
    public class SetCookieOnSubmit: umbraco.BusinessLogic.ApplicationBase {

    public SetCookieOnSubmit()
    {
    RecordService.RecordSubmitted +=
    new EventHandler<Umbraco.Forms.Core.RecordEventArgs>(RecordService_RecordSubmitted);
    }

    void RecordService_RecordSubmitted(object sender, Umbraco.Forms.Core.RecordEventArgs e)
    {
    umbraco.library.setCookie(e.Form.Id.ToString(), "1");
    }


    }
    }
  • Lilian Hughes 11 posts 31 karma points
    Mar 22, 2011 @ 15:57
    Lilian Hughes
    0

    Hi Tim,

    Thanks for that, again that seems to work also :)

    However, once I've completed the form I want to be redirected to the QueryString provided. So when I get the form to say thanks for submitting I check in jQuery the cookie existance and then redirect using document.location...

    This still feels like a Fudge to me.

    Thanks

    David

Please Sign in or register to post replies

Write your reply to:

Draft