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.
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)
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 = newFormStorage(); 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";
Also here's how you update security info programatically.
// load the security info var securityRepository = newUserFormSecurityStorage(); var security = securityRepository.GetUserFormSecurity(User.GetCurrent().Id, form.Id).FirstOrDefault(); var securityIsNew = false; if (security == null) { security = newUserFormSecurity(); 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);
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.
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.
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.
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)
ok sorted it all out myself, pretty easy in the end, if someone else is after the answer, here it is:
Also here's how you update security info programatically.
Hi Murray,
Can you post complete code and steps to create form programatically ?
Thanks,
Shrestha
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.
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
is working on a reply...