Copied to clipboard

Flag this post as spam?

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


  • Ian Gerdes 10 posts 81 karma points
    Sep 05, 2016 @ 18:38
    Ian Gerdes
    0

    hidden fields - current url

    Hi Nicholas

    hope this makes sense.

    im using the same form on events pages - name, email, telephone, enquiry.

    ideally is there a way of passing the current page url as a hidden field? or adding a field with event but dynamically input the field with @currentPage.title so when its submitted the client knows what page the form was submitted.

    i have updated to the latest version.

    Regards,

    Ian

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Sep 06, 2016 @ 00:30
    Nicholas Westby
    0

    There are a few ways I can think of doing this:

    • Custom Hidden Field Type. You can create a custom hidden field type. You can read about creating custom field types here. You could then have some JavaScript look for that field and then set the value to the current URL. Right now, you'll have to find the field by field ID (i.e., the funky GUID). If you like, I can modify the built-in Responsive Bootstrap Angular template to output a data attribute containing the field alias (e.g., so you can find a field with an alias of "currentUrl"). Alternatively, you could make your custom hidden field type be used specifically for the URL, in which case you could populate the value on the server side when the form is rendered.
    • Payload. In the Responsive.Bootstrap.Angular.cshtml file, there is an anonymous object that gets created and serialized to JSON. Part of that object is an associative array called "payload". Currently, that associative array contains only the form ID (see screenshot below). You could add the current URL to this payload as well, and Formulate will send it to the server when submitting the AJAX request. However, I forget if Formulate will include those payload fields in the default email handler that sends out emails when forms are submitted. If not, let me know and we can tinker with that to get something working. If it does include it in the email, it will probably refer to it as "Unknown Field" (again, we can discuss options if you prefer the name in the email to be more specific).

    Payload

  • Ian Gerdes 10 posts 81 karma points
    Sep 06, 2016 @ 12:22
    Ian Gerdes
    0

    hi Nicholas

    could you point me in the right direction of what to add in the payload?

    regards.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Sep 06, 2016 @ 15:07
    Nicholas Westby
    0

    Something like this should work:

    payload = new
    {
        FormId = Model.FormDefinition.FormId.ToString("N"),
        CurrentUrl = Request.Url
    };
    
  • Ian Gerdes 10 posts 81 karma points
    Sep 06, 2016 @ 20:10
    Ian Gerdes
    0

    hi Nicholas

    it doesnt send the url in the email.

    // Convert to a JSON string that can be consumed by Angular. var angularModel = Json.Encode(new { data = new { // The name of the form can be use for analytics. name = Model.FormDefinition.Name, // The form alias can be used for custom styles. alias = Model.FormDefinition.Alias, // The random ID can be used to uniquely identify the form on the page. // Note that this random ID is regenerated on each page render. randomId = Guid.NewGuid().ToString("N"), // The fields in this form. fields = fieldsData, // The rows that define the form layout. rows = rowsData, payload = new { FormId = Model.FormDefinition.FormId.ToString("N"), CurrentUrl = Request.Url }, url = "/umbraco/formulate/submissions/submit" } });

    }

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Sep 06, 2016 @ 21:22
    Nicholas Westby
    0

    I confirmed the same just now. The problem seems to be this line: https://github.com/rhythmagency/formulate/blob/887b3be63c51cc0bf500eb922a686a63ad6e304a/src/formulate.api/Controllers/SubmissionsController.cs#L59

    It is only allowing values that were submitted with a GUID key. Not that I recommend it, but here's a hack that worked for me just now:

    payload = new
    {
        FormId = Model.FormDefinition.FormId.ToString("N"),
        // A terrible, horrible hack.
        A9B9B38006D64E57B5FEB7E23B804D4E = Request.Url
    },
    

    In other words, I used a GUID as the key. And I confirmed that the email does actually say "Unknown Field" (followed by the currect URL).

    If you don't like that hack (I know I don't), here are some other options:

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Sep 06, 2016 @ 21:26
    Nicholas Westby
    0

    Another option would be to combine the above hack with a pull request. The pull request would implement a map between GUID's to field names (perhaps in a config file). That way, if Formulate sees the key "A9B9B38006D64E57B5FEB7E23B804D4E" (as in the example above), you could have it be mapped to a nicer name in the email (e.g., "Current URL").

    I'm also open to other alternatives if you have any ideas other than those I've so far presented.

  • Ian Gerdes 10 posts 81 karma points
    Sep 07, 2016 @ 16:09
    Ian Gerdes
    0

    hi Nicholas

    thanks for this.

    yes the unknown field isnt great but i have added it for now.

    could we try the pull request?

    i have added a "events" form field to one of the forms, ideally id like to pass the event title and possibly other details to that.

    plus the url.

    cheers

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Sep 07, 2016 @ 18:03
    Nicholas Westby
    0

    Sure thing. To ensure your pull request is accepted, first outline the changes you plan to make in a new issue here: https://github.com/rhythmagency/formulate/issues

    Let me know if you need any pointers on how to contribute to the Formulate core codebase.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Sep 12, 2016 @ 06:11
    Nicholas Westby
    0

    FYI, the URL and page name can now be included in emails in the latest version of Formulate (0.3.7).

Please Sign in or register to post replies

Write your reply to:

Draft