Copied to clipboard

Flag this post as spam?

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


  • Murray Roke 503 posts 966 karma points c-trib
    Oct 14, 2010 @ 00:39
    Murray Roke
    0

    Contour. Programatically create forms

    Hi I would like to create forms programatically.

    Various pages on our site need a basic form, all the forms are the same, BUT we want to keep entries into those forms separate.

    So I guess the best way to approach this is to clone a generic form for each place where we need to gather entries, howeverwe wish to have this clonging done programatically.

    Cheers.

    Murray.

  • Murray Roke 503 posts 966 karma points c-trib
    Oct 14, 2010 @ 01:14
    Murray Roke
    0

    Rather than 'clone' perhaps I should say 'create' as long as we can create from tempalte in the same way as can be done via the UI

    Oh yea, also need to ensure the user who created the 'node' is set as the creator of the 'form', so they can modify it if required (they should not be able to modify other administrators forms)

  • Murray Roke 503 posts 966 karma points c-trib
    Oct 14, 2010 @ 23:33
    Murray Roke
    1

    ok sorted it all out myself, pretty easy in the end, if someone else is after the answer, here it is:

    //create the form from the template
    var formStorage = new FormStorage();
    var xDoc = new System.Xml.XmlDocument();
    xDoc.Load(HttpContext.Current.Server.MapPath(@"~/umbraco/plugins/umbracoContour/templates/Event Registration Form.ucf"));
    var form = ImportExportHelper.ImportFormFromXml(xDoc,false);

    // set the name of the form
    form.Name = sender.Text + " Form";

    // save the form
    formStorage.InsertForm(form);
  • Murray Roke 503 posts 966 karma points c-trib
    Oct 15, 2010 @ 00:18
    Murray Roke
    0

    Also here's how you update security info programatically.

    // load the security info
    var securityRepository = new UserFormSecurityStorage();
    var security = securityRepository.GetUserFormSecurity(User.GetCurrent().Id, form.Id).FirstOrDefault();
    var securityIsNew = false;
    if (security == null)
    {
    security = new UserFormSecurity();
    security.User = User.GetCurrent().Id;
    security.Form = form.Id;
    securityIsNew = true;
    }

    // modify the security info
    security.HasAccess = true;
    security.SecurityType = global::Umbraco.Forms.Core.Enums.FormSecurityType.Full;
    security.AllowInEditor = true;

    // save the security info
    if (securityIsNew)
    securityRepository.InsertUserFormSecurity(security);
    else
    securityRepository.UpdateUserFormSecurity(security);
  • shrestha 2 posts 22 karma points
    Jan 14, 2011 @ 18:07
    shrestha
    0

    Hi Murray,

    Can you post complete code and steps to create form programatically ?

    Thanks,

    Shrestha

  • Murray Roke 503 posts 966 karma points c-trib
    Jan 15, 2011 @ 02:47
    Murray Roke
    0

    See my post above that starts "ok sorted..." the only part missing is where I created the "Event Registration Form.ucf" template file but I did that via the user interface, rather than programatically.

  • Clayton Snider 1 post 21 karma points
    Sep 29, 2011 @ 22:13
    Clayton Snider
    0

    How about adding workflow actions programmatically? We have a standard set of actions we would like to have on every form. I was hoping the workflow would carry over in a form template, but no luck.

    I would like to either setup a set of actions that get associated with all new forms or somehow trap the form save event and add any missing workflow actions programmatically.

    Thanks,

    Clayton

     

Please Sign in or register to post replies

Write your reply to:

Draft