AI OnAI Off
Hi Kenneth,
Check out the information on this blog post https://www.aperturelabs.biz/blog/creating-episerver-forms-v.
Optimizely Forms are based upon blocks and therefore can be created programmatically.
It may take a bit more coding than we would like, however it is possible.
Paul
@Paul McGann
Thank you for this.
Ended up with something like this, if it's the best approach I don't know, but it works for me now.
foreach (var item in fromForm.ElementsArea.Items)
{
if (item.ContentLink.ID == 0)
{
continue;
}
//create a new form element in that folder
var content = _contentLoader.Get<IContent>(item.ContentLink);
var contentType = _contentTypeRepository.Load(content.ContentTypeID);
var formElement = _contentRepository.GetDefault<IContent>(formAssetFolder.ContentLink, contentType.ID);
formElement.Name = content.Name;
var from = content as ElementBlockBase;
var to = formElement as ElementBlockBase;
to.Label = from.Label;
to.Description = from.Description;
//save the edited form element
_contentRepository.Save((IContent)to, SaveAction.Publish, AccessLevel.NoAccess);
writeableForm.ElementsArea.Items.Add(new ContentAreaItem { ContentLink = formElement.ContentLink });
}
Kenneth
@Kenneth For using the GUI, there is also this:
Gotcha’s with reusing Episerver Forms ElementBlocks (optimizely.com)
Nils
What I have tried is something like this:
Where I have found both forms created. And when I look at the new form all the elements are there, the problem is not a new copy, it is the same element in both forms. So if I make a change in one of the forms, it changes in both. Is there anyway to f.ex loop through all the items of the ElementsArea and create a new one based on the Element?