Copied to clipboard

Flag this post as spam?

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


  • David Whiteford 26 posts 79 karma points
    Jan 22, 2015 @ 18:09
    David Whiteford
    0

    Umbraco 7.2.1 - Forms - Custom Layout

    Hi,

    I have followed the instructions for customising a single form layout in Forms (was Contour) as shown here:

    http://our.umbraco.org/projects/umbraco-pro/contour/documentation/Developer/Custom-Markup/

    Obviously the path is now different and I assume it is: /views/partials/forms/{GUID}/Form.cshtml

    This however does nothing and it still renders the Form.cshtml in the root of the views/partials/forms/ folder.

    I have triple checked the GUID is correct.

    Can anyone confirm this actually works in 7.2.1 now that Forms are built into Umbraco?

    Any help is much appreciated.

    Regards Dave

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 22, 2015 @ 19:23
    Jan Skovgaard
    0

    Hi Dave

    Do you have any kind of caching setup, which might be the issue? Does it help if you recycle the app pool?

    /Jan

  • David Whiteford 26 posts 79 karma points
    Jan 23, 2015 @ 09:43
    David Whiteford
    0

    Yeah I have tried:

    • recycling app pool
    • stop/start app pool
    • stop/start website
    • clear cache, restart browser
    • delete umbraco.config so it re-creates it

    Can you check whether this works for you in 7.2.1?

    Thanks for your reply

    Dave

  • David Whiteford 26 posts 79 karma points
    Jan 23, 2015 @ 12:24
    David Whiteford
    101

    Ok, I've managed to get it working but I had to decompile the dll the figure it out. The code that checks for the override view is:

    if (string.IsNullOrEmpty(view))
            view = Path.Combine(Config.ViewsPath, "Form.cshtml");
          else if (!view.StartsWith("~") && !view.StartsWith("/"))
            view = Path.Combine(Config.ViewsPath, view);
          return (ActionResult) this.PartialView(view, (object) model);
    

    Where view is a string passed into the Render Action on the UmbracoForms Controller and the Config.ViewsPath = "~/Views/Partials/Forms".

    The "view" string is built up anywere, just passed in, so I edited the InsertUmbracoForm.cshtml MacroPartial to do:

    var s = Model.MacroParameters["FormGuid"].ToString();
    var g = new Guid(s);
    
    string customFile = "/Views/Partials/Forms/" + s + "/Form.cshtml";
    
    string view = (System.IO.File.Exists(Server.MapPath(customFile))) ? customFile : "";
    
    Html.RenderAction("Render", "UmbracoForms", new { formId = g, view = view });
    

    This is now functioning correctly.

    I don't know whether I have missed something obvious but this is the only way I can get this to work.

    Any advice/comments are appreciated.

    Cheers

  • Soren Fruergaard 9 posts 29 karma points
    Jan 28, 2015 @ 11:21
    Soren Fruergaard
    0

    Hi,

    I have also experienced this problem, where I don't know where I should place the custom form files.

    /views/partials/forms/{GUID}/Form.cshtml -  also seems as the logical place for me to put the custom files, just as you did in Contour.

    Davids solution for the InsertUmbracoForm.cshtml MacroPartial, works perfect, but what if you just wanted to make a simple change to FieldType.Textfield.cshtml for a single form?

    Thanks in advance

    /Soren

  • David Whiteford 26 posts 79 karma points
    Jan 28, 2015 @ 11:41
    David Whiteford
    0

    Hi Soren,

    Glad my solution works for you.

    From inspecting the decompiled code for Contour I am led believe that the field type should work - I have not needed to do this, but I can see code checking for a file at the below location:

    /views/partials/forms/{GUID}/FieldType.Textfield.cshtml

    Let me know if it works for you.

    Cheers

  • Soren Fruergaard 9 posts 29 karma points
    Jan 28, 2015 @ 13:05
    Soren Fruergaard
    0

    Hi

    Thank you for the fast response.

    I think I have located the error FieldViewResolver:

    public static string GetFieldView(string formAlias, string viewName, string fieldName)
            {
                if (fieldName.Length > 75)
                {
                    fieldName = fieldName.Substring(0, 75);
                }
                viewName = FieldViewResolver.FolderName(viewName);
                string result;
                if (File.Exists(HttpContext.Current.Server.MapPath(string.Format("{0}/Forms/{1}/Fieldtype.{2}.cshtml", Config.ViewsPath, formAlias, viewName))))
                {
                    result = string.Format("{0}/Forms/{1}/Fieldtype.{2}.cshtml", Config.ViewsPath, formAlias, viewName);
                }
                else
                {
                    result = string.Format("{0}/FieldTypes/Fieldtype.{1}.cshtml", Config.ViewsPath, viewName);
                }
                return result;
            }

    The config.viewsPath is "~/Views/Partials/Forms"

    Which makes the first check "~/Views/Partials/Forms/Forms/{GUID}/FieldType.Textfield.cshtml"; otherwise it returns "~/Views/Partials/Forms/{GUID}/FieldType.Textfield.cshtml"

    /Soren

  • David Whiteford 26 posts 79 karma points
    Jan 28, 2015 @ 13:38
    David Whiteford
    0

    Good spot Soren - I guess you need to flag that as a bug to Umbraco so that path can be resolved in a future release (I assume it isnt meant to be /Forms/Forms/

    Cheers

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    Jul 09, 2015 @ 19:37
    Chris Houston
    0

    Hi Guys,

    Just a follow up as to how we have used this, we have a view that allows forms to be added to a drop down at the top of the page, we needed these to be formatted differently to those forms that are used within the body of a content page, rather than using the Form ID we have just used the following so all the forms used in the drop downs use the same form view, all others use the standard form view.

    var customFile = "/Views/Partials/Forms/DropDownForms/Form.cshtml";
    var view = (System.IO.File.Exists(Server.MapPath(customFile))) ? customFile : "";
    
    Html.RenderAction("Render", "UmbracoForms", new { formId = g, view });
    

    Thanks to this thread as I couldn't find any documentation about this functionality, in-fact there is another thread that mentions this is currently not possible, so I can confirm as of the current version 4.1.4 it is possible :)

  • Nick 101 posts 123 karma points
    May 19, 2016 @ 15:09
    Nick
    0

    Okay it's May 2016 and this bug is still there!

    Thanks David for your fix, this was driving me nuts for a while.

Please Sign in or register to post replies

Write your reply to:

Draft