How to use CreateFormEntry?

Posted by Community Admin on 03-Aug-2018 06:48

How to use CreateFormEntry?

All Replies

Posted by Community Admin on 17-Mar-2011 00:00

What is the "entryType" string parameter it asks for when creating form entries programmatically?

FormsManager.GetManager().CreateFormEntry(string entryType)

Posted by Community Admin on 17-Mar-2011 00:00

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

Posted by Community Admin on 17-Mar-2011 00:00

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?

Posted by Community Admin on 17-Mar-2011 00:00

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);

Seems to work, but still trying to figure out how to handle multiple answer items like checkboxes. This is what I did to extend the API which I hope helps someone (let me know if anyone notices anything wrong here):

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();

Thanks!

Posted by Community Admin on 27-May-2011 00:00

@Basem

Thank you very much for the provided code. This is exactly what I was looking for.

Best wishes

Michael

Posted by Community Admin on 11-Nov-2011 00:00

Very thanks Basem.

It was very helpful for me, too.

This thread is closed