Copied to clipboard

Flag this post as spam?

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


  • jonok 258 posts 474 karma points
    Jun 07, 2017 @ 23:45
    jonok
    0

    How to display hidden input value in email template

    I have seen a few threads about how to include the page name in the email template, but none seem to give a full solution. I am using javascript to populate a hidden input with the page name, but I'm not sure how to display this hidden input value in the email template partial view? This hidden input isn't being added via the Form builder fields, I have hard coded it in in the 'Render.cshtml' file, eg...

    <input type="hidden" class="page-name-input" name="PageName" value="" />
    

    And in the header I have a meta tag for the page name...

    <meta name="page.name" content="@Model.Content.Name">
    

    And then I use js to populate the hidden field...

        if($('.page-name-input').length) {
            var pageName = $("meta[name='page.name']").attr('content');
            $(".page-name-input").val(pageName);
        }
    

    Has anybody got information about how to display this hidden input value in the email template partial view?

  • Nicholas Westby 1923 posts 6445 karma points c-trib
    Jun 08, 2017 @ 04:52
    Nicholas Westby
    0

    This hidden input isn't being added via the Form builder fields

    Why not? I expect that'd solve your issue.

    Personally, I'd create a new field type, then in the CSHTML file for that field, output a hidden field that contains the page name. No need for any JavaScript.

  • jonok 258 posts 474 karma points
    Jun 15, 2017 @ 23:42
    jonok
    0

    Why not? I expect that'd solve your issue.

    The content and forms are being managed by one of my clients, and it's a bit clunky to ask them to remember to add a custom hidden field every time they create a new form. They are going to have lots of different forms and CTA's on many different pages throughout the site - was just wondering if it could be done programmatically without relying on the CMS user to add the extra hidden field.

    But thanks for your suggestion of creating a new field type, that will work if there is no other solution.

  • Nicholas Westby 1923 posts 6445 karma points c-trib
    Jun 17, 2017 @ 08:01
    Nicholas Westby
    1

    it's a bit clunky to ask them to remember to add a custom hidden field every time they create a new form

    For things that are harder to remember, it can be useful to add a dashboard to the Umbraco Forms section with instructions (scroll down to "Add a Custom Dashboard"): https://code101.net/clean-up-your-umbraco-dashboards-f42b256d539d

    But thanks for your suggestion of creating a new field type, that will work if there is no other solution.

    You might be able to use the API to automatically add the field to the form when the form is first created. If not, I think forms are stored as JSON in the latest versions of Umbraco Forms, so you could programmatically modify those JSON files if necessary. A bit hacky, but if you really want to automate it then that may be a viable option.

    Another option would be for you to modify the Form.cshtml file that handles the rendering of the form. At least, I think that's the file (it was back when Umbraco Forms was still known as Contour). If the form doesn't contain the custom field, you can instead render a message that says "looks like you forgot to add such and such a field, here's how you do it." That way, at least the person creating the form can be notified when they forgot something.

Please Sign in or register to post replies

Write your reply to:

Draft