Copied to clipboard

Flag this post as spam?

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


  • Simon Jackson 11 posts 31 karma points
    Mar 02, 2016 @ 13:17
    Simon Jackson
    0

    Umbraco Forms - API?

    Hi,

    After an Umbraco guru for some quick advise :)

    We're integrating Umbraco forms with another system. We have an external service that needs to be able.

    • Iterate the forms collection
    • Iterate the form fields collection.

    Can you please point us in the direction of how to do this programmatically from a service that is not on the Umbraco server?

    This has nothing to do with the data that is submitted but more to do with the form schema.

    Many thanks for your help

    Si

  • Simon Jackson 11 posts 31 karma points
    Mar 02, 2016 @ 14:16
    Simon Jackson
    0

    In the end I gave up and worked around the issue using an event handler to post information out to the other system.

    Still interested in other answers and suggestions.

        using Umbraco.Core;
        using Umbraco.Forms.Core;
        using Umbraco.Forms.Data.Storage;
    
        namespace blar.Forms
        {
            public class UmbracoFormsListener : ApplicationEventHandler
            {
                protected override void ApplicationStarted(
                    UmbracoApplicationBase umbracoApplication,
                    ApplicationContext applicationContext)
                {
                    //Listen for when form changes  is being saved
                    FormStorage.Created += new EventHandler<FormEventArgs>(FormStorage_FormCreated);
                    FormStorage.Saved += new EventHandler<FormEventArgs>(FormStorage_FormSaved);
                    FormStorage.Deleted += new EventHandler<FormEventArgs>(FormStorage_FormDelete);
                }
       ....
      }
    
  • Robert Smith 18 posts 118 karma points
    Apr 27, 2017 @ 23:26
    Robert Smith
    0

    Hello,

    I hope this is the correct thread to query. If not, please accept my apologies.

    I am trying to find out more about the Forms API. I have read the documents on this site which confirm that data queried from Forms comes back as a dynamic object and that the static methods can be found within Umbraco.Forms.Mvc.DynamicObjects.Library.

    Unfortunately, I am a newbie to Umbraco, Razor, and C#. I have been learning more about C# and how classes and namespaces work, but my background is JS, not C#.

    Through trial and error, and cobbling together information from other threads, I have been able to retrieve the prevalues for a list of options in the form as follows:

        @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @using Umbraco.Forms.Mvc.DynamicObjects
    
    
    <ul>
     @foreach (dynamic record in Library.GetApprovedRecordsFromFormOnPage(@CurrentPage.Id, "myFormID").OrderBy("Created"))
     {
    
    <li>
    
             @foreach( var field in record.RecordFields )
    {
    
        var prev1=field.Value.Field.PreValues[0];
        var prev2=field.Value.Field.PreValues[1];
        }
        }
    

    However, how would I go about finding this sort of thing out in the future via a more direct route? I can't find any documentation which describes the deeper levels within the class beyond what is provided for in the brief discussion on the above-linked page.

    I was able to list the properties of the returned Dynamic Records by using the following Razor code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @using Umbraco.Forms.Mvc.DynamicObjects
    
    @foreach (dynamic record in Library.GetApprovedRecordsFromFormOnPage(@CurrentPage.Id, "myFormID").OrderBy("Created"))
     {
    foreach(var prop in record.GetType().GetProperties()) {
    
        <p>@prop.Name</p>
    
    }
    }
    

    This information, however, is already available in the documentation linked above. How would I find out what is available within RecordFields (for example)?

    Thank you.

Please Sign in or register to post replies

Write your reply to:

Draft