Copied to clipboard

Flag this post as spam?

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


  • Mark 255 posts 612 karma points
    Nov 20, 2014 @ 19:35
    Mark
    0

    Mvc: "Customize for a specific field an a form" not working

    Umbraco: 6.1.5
    Contour: 3.0.17

    This Umbraco Contour help page has a section at the bottom entitled: Customize for a specific field an a form

    I have a checkbox field at the bottom of the page that says this in the caption:

    Click this button to confirm you agree to the terms and conditions and privacy policy

    So inside the folder (I've verified the form GUID is correct):

    \Umbraco\Plugins\umbracoContour\Views\Forms\67f4bc95-98a1-4f24-9f76-cb2a33e1164d

    I have created the file called:

    Clickthisbuttontoconfirmyouagreetothetermsandconditionsandprivacypolicy.cshtml

    Which contains this code (standard checkbox cshtml file with a paragraph inserted at line 2):

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    

    I agree to my personal data being stored. See Terms & Conditions and Privacy Policy.

    data-val="true" data-val-requiredcb="@Model.RequiredErrorMessage"} @if (Model.ContainsValue(true) || Model.ContainsValue("true") || Model.ContainsValue("on")) {checked="checked"} />

    For some reason the added paragraph doesn't appear on the back end or front end when adding the macro (razor version) to the page. Any idea why? The help page says this:

    ~\umbraco\plugins\umbracoContour\Views\Forms\85514c04-e188-43d0-9246-98b34069750c\FieldNameWithoutSpaces.cshtml

    The form field doesn't have a "Field Name" field that I can see, only a "Caption" field.

    Any idea what I'm doing wrong?

  • Mark 255 posts 612 karma points
    Nov 20, 2014 @ 21:17
    Mark
    1

    Problem solved. Looking at Umbraco.Forms.Mvc.dll in reflector showed UmbracoFormsBusinessLogic.FieldViewResolver.GetFieldView method truncates the field name (before removing non regex word characters) to 0x4b (75 decimal) characters:

    Click this button to confirm you agree to the terms and conditions and priv

    So the filename needed to be:

    clickthisbuttontoconfirmyouagreetothetermsandconditionsandpriv.cshtml

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Nov 20, 2014 @ 21:56
    Nicholas Westby
    1

    Nice detective work! I really hope the new version of Contour (to be called Umbraco Forms) has a better way of customizing things like this (e.g., with a field alias so the caption can be changed without affecting behaviors like custom fields).

  • Mark 255 posts 612 karma points
    Nov 21, 2014 @ 11:59
    Mark
    100

    For anyone else wanting to insert an html snippet into a form that doesn't require editing capabilities on the back end. Here's the simple 5 minute hacky solution I came up with (when using Umbraco in Mvc mode), that took me over 2 hours to work out:

    1. At the position you want the Html inserted, create a hidden field on the form with a name (caption) like "Do not edit or remove field one". (Hidden field makes the Html snippet full width, as the label is not displayed). Note: caption should be less than 75 characters to avoid problems discussed previously).
    2. In the webroot folder, create your html snippet by adding it into this file (as per instructions on this page): \umbraco\plugins\umbracoContour\Views\Forms\85514c04-e188-43d0-9246-98b34069750c\FieldNameWithoutSpaces.cshtml (no need for a @model, and obviously the form GUID needs to be changed, and the field name replaced, lower case, without spaces).
    It didn't cause us problems when emailing the form, although the empty value did get passed through in the email workflow, so long as you can live with that. One option would be to use an XSLT email and omit the field, but we didn't bother for our purposes.
Please Sign in or register to post replies

Write your reply to:

Draft