Copied to clipboard

Flag this post as spam?

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


  • Jay Crowe 36 posts 167 karma points
    May 20, 2019 @ 13:13
    Jay Crowe
    0

    Formulate Get ConfiguredFormInfo By Form Id

    Hi,

    I have created a Macro Parameter for the Formulate Form Picker. This works fine and I can get the form Id back from the Macro Parameter. I now need to get a ConfiguredFormInfo model from that Form Id. Has any one done this? Or does Formulate have any helpers I can use?

    Cheers, Jay

  • Nicholas Westby 1893 posts 6332 karma points c-trib
    May 20, 2019 @ 16:43
    Nicholas Westby
    0

    This may help: https://our.umbraco.com/packages/backoffice-extensions/formulate/formulate-questions/81853-formulate-and-web-forms

    In particular this commit: https://github.com/Nicholas-Westby/web-formulate/commit/4125a398d48cf7589ec28b99d62ef157ccfd80c7

    It's been a while, but it looks like I got Formulate working with a macro (in this case, on a WebForms project, but should translate well to Razor). I suppose this is the most relevant bit of code you'll want to focus on:

            // Variables.
        var context = Umbraco.Web.UmbracoContext.Current;
        var content = context.PublishedContentRequest.PublishedContent;
    
         // Get a view model for the picked form.
        var pickedForm = Umbraco.Web.PublishedContentExtensions
            .GetPropertyValue<formulate.app.Types.ConfiguredFormInfo>(content, "contactForm");
        var vm = formulate.api.Rendering.GetFormViewModel(pickedForm.FormId, pickedForm.LayoutId,
            pickedForm.TemplateId, content);
    
         // Pass form model to user control.
        formRenderer.FormModel = vm;
    

    Let me know if you have questions.

  • Jay Crowe 36 posts 167 karma points
    May 20, 2019 @ 16:53
    Jay Crowe
    0

    Thanks for the reply Nicholas.

    This doesnt seem to work at I get a null exception reference when trying to get: var content = context.PublishedContentRequest.PublishedContent;

  • Nicholas Westby 1893 posts 6332 karma points c-trib
    May 20, 2019 @ 18:06
    Nicholas Westby
    0

    I suggest digging in a bit more. I bet there is a way to do it, though I don't have the method off the top of my head.

    All that line is really doing is getting the current page.

  • Jay Crowe 36 posts 167 karma points
    May 20, 2019 @ 20:27
    Jay Crowe
    0

    I just can't get the ConfiguredFormInfo Model at all. All I get back from the Macro Parameter is the Id of the Form nothing else. And then I cant seem to get the form using the ID what so ever. I might have to change the way I am using the Form Picker and move it away from the Macro and just put it onto the Document Type itself and just use the Macro to display the form.

  • Jay Crowe 36 posts 167 karma points
    May 20, 2019 @ 20:36
    Jay Crowe
    0

    Im using App Data models this wouldnt affect it would it?

  • Nicholas Westby 1893 posts 6332 karma points c-trib
    May 20, 2019 @ 21:12
    Nicholas Westby
    0

    I might have to change the way I am using the Form Picker and move it away from the Macro and just put it onto the Document Type itself and just use the Macro to display the form.

    I personally don't use Umbraco macros and wouldn't recommend them, unless you're using Umbraco Grid (which are a different type of macro).

    I tend to build widget-based websites, so I have a "form" widget with a Formulate form picker property: https://skrift.io/articles/archive/building-umbraco-websites-with-archetype-widgets-and-ditto/

    But putting the form picker property on the doctype itself would be a fine approach too.

    Im using App Data models this wouldnt affect it would it?

    Not sure what you mean by "App Data models". Are you using Models Builder and the C# classes for the models are placed in the App_Data folder? If so, I imagine that'd be fine, but I haven't tried combining models builder and Formulate before. Worth a shot.

Please Sign in or register to post replies

Write your reply to:

Draft