Copied to clipboard

Flag this post as spam?

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


  • MuirisOG 382 posts 1284 karma points
    Dec 13, 2016 @ 15:09
    MuirisOG
    0

    Formulate and Web Forms

    Hi there,

    Can you explain the customisations that are needed to get Formulate to work with WebForms?

    many Thanks

    muirisOG

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 13, 2016 @ 15:20
    Nicholas Westby
    0

    I've never tried it, but shouldn't be too hard to get it to work.

    I'm assuming you're starting with a page that looks a bit like this: http://www.formulate.rocks/render-form

    Replace this line:

    @Html.Partial("~/Views/Partials/Formulate/RenderForm.cshtml", vm)
    

    With a modified version of this code: https://github.com/rhythmagency/formulate/blob/e2f74581730d72c0bd806616320972128ddfbe43/src/Website/Views/Partials/Formulate/Responsive.Bootstrap.Angular.cshtml

    You'll have to make a couple changes. For example, there will no longer be a model, as you won't be in a Razor partial. You can use the "vm" variable instead.

    If you want to componentize it, you certainly should be able to toss that code into a user control. You'll just have to make sure you pass the view model to the user control from your page.

    Let me know if you need any clarifications.

  • MuirisOG 382 posts 1284 karma points
    Dec 14, 2016 @ 17:21
    MuirisOG
    0

    Thanks Nicholas

    but you are dealing with a Web Forms dinosaur here, so your explanation was a bit over my head.

    I'm in phase I of migrating our site to Umbraco in its current form using Web Forms, and phase II will be to move to MVC.

    Having said that, I did manage to get a form working by creating a file called formulateMacro.cshtml in the /Views/MacroPartials folder, and copying and pasting the code in your "render-form" page.

    The only change I made was to your second line of code, i.e.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    was changed to

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    At the moment, the template for the page holding the form has only one job, i.e. to act as a placeholder for the formulateMacro macro.

    I didn't change anything else, though, so I'm guessing I'll hit a few problems when I attempt to integrate it into my existing page templates.

    Although I received an email after submitting the form, I'm still a bit bewildered as to how it all works.

    My Umbraco learning curve continues, eh...

    thanks again,

    muiris

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 14, 2016 @ 20:20
    Nicholas Westby
    0

    It seems that you have converted this Razor view into a partial view macro: http://www.formulate.rocks/render-form

    You are correct that you'll run into problems later, as that partial view is now rendering the entirety of your page, including the <html>, <head>, and <body> tags.

    Since you are using WebForms with Umbraco, I am assuming that you typically have a file called "MyPage.master" (i.e., a masterpage, which is how Umbraco makes use of WebForms if you are using WebForms rather than Razor views).

    Assuming you have MyPage.master, most of the code from here would go in that page: http://www.formulate.rocks/render-form

    You've also pointed out an interesting fact. That is, Umbraco supports some interoperability between WebForms and Razor in the form of macros. You can create macros as WebForms user controls, or as Razor partial views. That means you could basically leave Responsive.Bootstrap.Angular.cshtml unchanged (well, some minor changes), so long as you convert it so that it's used as a macro (and then you could render that macro from a masterpage or a razor view).

    If you want to go down that road, be mindful that you'll have to somehow coordinate passing data from your MyPage.master to the Responsive.Bootstrap.Angular.cshtml macro, as passing data to macros can be quirky in Umbraco. One way to do that would be to have the macro fetch the picked form off of the current page, but that could in turn cause complications (e.g., if you are storing forms in an Archetype, grid, or nested content rather than directly on a property on the current page).

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 15, 2016 @ 03:50
    Nicholas Westby
    0

    By the way, let me know if you found particular portions of my above explanation confusing and I'd be happy to dive into details.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 15, 2016 @ 06:05
    Nicholas Westby
    100

    I went ahead and created an example repo: https://github.com/Nicholas-Westby/web-formulate

    Download it, run the solution, and you'll see a Formulate form rendered just like the screenshot shown on the repo Readme.

    Take a look at the code and the commit history to see how it works.

  • MuirisOG 382 posts 1284 karma points
    Dec 15, 2016 @ 15:51
    MuirisOG
    0

    Nicholas

    thanks for the repo, but I had a few problems getting it to run... maybe too many to spend a lot of time on (i.e. I struggled with items in the /bin folder so I copied everything from another instance, and the formulate stuff from another site I was developing, I upgraded MySql and .NET, but it really got stuck because it didn't know what frm:Render was, or FormModel - probably needs a tagprefix in the web.config).

    I had started to work my way through everything, but in the end, I thought my time would be better spent on, as you suggested, getting the MyPage.master option working.

    Thanks again

    muiris

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 15, 2016 @ 16:21
    Nicholas Westby
    0

    Strange. I built this at home last night, then just tried cloning at work this morning and it worked perfectly. Are you using an older version of Visual Studio (e.g., Visual Studio 2013)? If so, it may not be running NuGet package restore. Visual Studio 2015 runs that automatically:

    Package Restore

    The "frm:Render" tag was defined at the top of the Home.master file:

    Form Render Tag Definition

    FormModel is defined in RenderFormulateForm.ascx.cs:

    Render Formulate Form

    In any event, if you've got something that works for you, happy to hear it. Let me know if you have any questions.

  • MuirisOG 382 posts 1284 karma points
    Dec 15, 2016 @ 16:28
    MuirisOG
    0

    You are correct, I am using VS2013 and sorry, I didn't think to look Home.Master. In any case, the umbraco backoffice was giving me enough info so I could see what you were trying to achieve.

    I'll see about getting me a copy of VS2015, and I'll try running it again.

    many thanks,

    Muiris.

  • MuirisOG 382 posts 1284 karma points
    Dec 16, 2016 @ 17:27
    MuirisOG
    1

    After a little research, I found VS2013 has the exact same settings for NuGet.

    I've got your example site up and running and received an email from the test form you created.

    I've also marked your earlier post as the solution.

    Many thanks for this, I really appreciate all the help you gave.

    I'll make some amendments to the site I'm developing and try out Formulate there.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 16, 2016 @ 19:10
    Nicholas Westby
    0

    Awesome, happy to hear it seems to be working out so far. Let me know if you run across any more issues or have any more questions.

Please Sign in or register to post replies

Write your reply to:

Draft