Copied to clipboard

Flag this post as spam?

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


  • René 327 posts 852 karma points
    Nov 30, 2017 @ 14:38
    René
    0

    Umbraco form 6.0.5 - Hiddenfield error Page id

    Hi

    Current installed version of Umbraco Forms: "6.0.5" Umbraco version 7.7.6

    I have this strange error on Umbraco forms

    I have to get the page id and send with the form.

    When i have the page id i can get the url of the page and the pagename.

    var pageUrl = siteDomain + Umbraco.TypedContent(Model.DynamicFields.id).Url;
    

    For testing i have added the page id as a short answer.

    (I have it in a hidden field in production)

    enter image description here

    But when i post the form i get a different url.

    The page id is different from the value posted by the form.

    The correct id is 8083.

    enter image description here

    René

  • René 327 posts 852 karma points
    Nov 30, 2017 @ 22:09
    René
    0

    Hi

    I have been looking closer in to this.

    It is the value on the hidden field, it shows the previous page i had visited.

    René

  • René 327 posts 852 karma points
    Nov 30, 2017 @ 22:39
    René
    0

    Hi

    Some more information.

    Now i have tried to wait some time.

    The first time i submit the form it is correct.

    The second time i get the previous ID send.

    If i change the browser and submit the form i get the wrong ID.

    It seems for me it is some cache in Umbraco Form. Any ideas would be great..

    Thanks in advance.

    René

  • René 327 posts 852 karma points
    Dec 04, 2017 @ 09:32
    René
    0

    Hi Umbraco form team

    Is there any one :-)

    René :)

  • René 327 posts 852 karma points
    Dec 05, 2017 @ 11:36
    René
    100

    HI

    If anyone comes here i made a custom datatype for the solution.

    In app folder: Add a new class HiddenFieldPageId.cs and add this Add this (Important the "this.Name" must be the name of the file ~/Views/Partials/Forms/Themes/default/Fieldtypes/FieldType.HiddenFieldPageId.cshtml, without "Fieldtype." )

    public class HiddenFieldPageId : FieldType
    {
        public HiddenFieldPageId()
        {
            //Provider
            this.Id = new Guid("d6a2c406-cf89-11de-b075-55b055d89593");
            this.Name = "HiddenFieldPageId";
            this.Description = "Renders a hiddenfield With value of currentpageid";
            this.Icon = "icon-autofill";
            this.DataType = FieldDataType.String;
            this.SortOrder = 10;
        }
    }
    

    In the folder Views\Partials\Forms\Themes\default\Fieldtypes\ copy the Fieldtype.Hiddenfield and rename to FieldType.HiddenFieldPageId.cshtml and paste the code below.

    @model Umbraco.Forms.Mvc.Models.FieldViewModel @{
    var umbraco = new UmbracoHelper(UmbracoContext.Current);
    var currentPage = umbraco.TypedContent(UmbracoContext.Current.PageId);}
    

    Add the code to the Views\Partials\Forms\Emails\Example-template.cshtml

    var pageId = Model.DynamicFields.pageId;
    var pageUrl = siteDomain + Umbraco.TypedContent(pageId).Url;
    var pageName = Umbraco.TypedContent(pageId).Name;
    

    Now you have access to the pagename and url via the id.

    Build the solution and add the new formfield to the form

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft