+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / How to use CreateFormEntry?

How to use CreateFormEntry?

6 posts, 1 answered
  1. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    17 Mar 2011
    Link to this post
    What is the "entryType" string parameter it asks for when creating form entries programmatically?

    FormsManager.GetManager().CreateFormEntry(string entryType)
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Mar 2011
    Link to this post
    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
    Answered
  3. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    17 Mar 2011
    Link to this post
    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?
  4. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    17 Mar 2011
    Link to this post
    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!
  5. Michael
    Michael avatar
    5 posts
    Registered:
    03 Nov 2010
    27 May 2011
    Link to this post
    @Basem

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

    Best wishes

    Michael
  6. Volkan Demirpence
    Volkan Demirpence avatar
    12 posts
    Registered:
    11 Nov 2006
    11 Nov 2011
    Link to this post
    Very thanks Basem.

    It was very helpful for me, too.
6 posts, 1 answered