How to use CreateFormEntry?
What is the "entryType" string parameter it asks for when creating form entries programmatically?
FormsManager.GetManager().CreateFormEntry(string entryType)
Hi Basem,
Generally this is the form type
Telerik.Sitefinity.DynamicTypes.Model.sf_myformname
var manager = FormsManager.GetManager();
FormEntry entry = manager.CreateFormEntry(String.Format("0.1", manager.Provider.FormsNamespace, this.FormData.Name));
Regards,
Ivan Dimitrov
the Telerik team
Thanks but I'm still having trouble coming up with a sample though.. how do I add the values to "entry" then saving the response to the form. Can you take a step or two further please?
I used reflector to get some more hints from:
Telerik.Sitefinity.Modules.Forms.Web.UI.FormControl
Here is a custom extension I had to create to add entry items to the form. Now I can do this:
var manager = FormsManager.GetManager();
var form = manager.GetFormByName(
"sf_testform"
);
//COLLECT INPUT VALUES
Dictionary<
string
,
string
> inputs =
new
Dictionary<
string
,
string
>();
inputs.Add(
"FormTextBox_C008"
,
"test1"
);
//STORE INPUTS
form.SaveEntry(inputs);
public
static
void
SaveEntry(
this
FormDescription form, IDictionary<
string
,
string
> inputs)
FormsManager manager = FormsManager.GetManager();
FormEntry entry = manager.CreateFormEntry(form.EntriesTypeName);
//ADD ALL INPUT VALUES
foreach
(var item
in
inputs)
entry.SetValue(item.Key, item.Value);
//SAVE USER RELATED INFO
HttpContext context = HttpContext.Current;
if
(context !=
null
)
entry.IpAddress = context.Request.UserHostAddress;
entry.UserId = SecurityManager.GetCurrentUser().UserId;
//SAVE LANGUAGE FOR MULTI-LINGUAL SUPPORT
if
(AppSettings.CurrentSettings.Multilingual)
entry.Language = System.Globalization.CultureInfo.CurrentUICulture.Name;
//UPDATE IDENTIFICATION AND TRACKING
form.FormEntriesSeed = form.FormEntriesSeed + 1L;
entry.ReferralCode = form.FormEntriesSeed.ToString();
entry.SubmittedOn = System.DateTime.UtcNow;
//SAVE TO STORAGE
manager.SaveChanges();
@Basem
Thank you very much for the provided code. This is exactly what I was looking for.
Best wishes
Michael
Very thanks Basem.
It was very helpful for me, too.