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

Forums / General Discussions / Create form responses programmatically?

Create form responses programmatically?

7 posts, 0 answered
  1. Raymond Dowe
    Raymond Dowe avatar
    37 posts
    Registered:
    10 Mar 2010
    08 Jan 2013
    Link to this post
    Can anyone provide an example of how to do this? I'm an experienced programmer, but I'm not very familiar with the Sitefinity framework / data model.
  2. Randy Hodge
    Randy Hodge avatar
    96 posts
    Registered:
    03 Nov 2014
    11 Jan 2013
    Link to this post
    Hello Raymond,

    Here is a sample that will create a form response.
    void GenerateFormResponse()
    {
        FormsManager formsMgr = FormsManager.GetManager();
        formsMgr.Provider.SuppressSecurityChecks = true;
     
        var form = formsMgr.GetFormByName("sf_testform1");
     
        if (form != null)
        {
            FormEntry entry = formsMgr.CreateFormEntry(String.Format("{0}.{1}", formsMgr.Provider.FormsNamespace, form.Name));
     
            entry.SetValue("FormTextBox_C001", "Angus");      //first name
            entry.SetValue("FormTextBox_C003", "Thermopile"); //last name
     
            entry.IpAddress = Page.Request.UserHostAddress;
            entry.SubmittedOn = DateTime.UtcNow;
            entry.UserId = ClaimsManager.GetCurrentUserId();
            if (SystemManager.CurrentContext.AppSettings.Multilingual)
            {
                entry.Language = CultureInfo.CurrentUICulture.Name;
            }
            form.FormEntriesSeed++;
            entry.ReferralCode = form.FormEntriesSeed.ToString();
     
            formsMgr.SaveChanges();
        }
     
    }

    Where "sf_testform1" is the name of your form which you can find under the "Advanced" section of the form designer and "FormTextBox_C001" is the name of the first form control in your form which you set under the "Advanced' section in the form control designer.

    I hope you find this useful.

    Regards,
    Randy Hodge
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Bhavik
    Bhavik avatar
    1 posts
    Registered:
    28 Sep 2012
    14 Jul 2014
    Link to this post

       You can also try this

    using (var fluent = App.WorkWith())
                  {
                      fluent.Forms()
                          .Form("sf_empdetails")
                          .Entry()
                          .CreateNew(System.Guid.NewGuid())
                          .SetFieldValue("FormTextBox_C001", name)
                          .SetFieldValue("FormTextBox_C002", name2)
                                     .SaveChanges();
                  }

  4. Paula
    Paula avatar
    2 posts
    Registered:
    23 May 2014
    17 Jul 2014 in reply to Bhavik
    Link to this post

    I wonder how to add other values to the entry with fluent api like
    entry.UserId

  5. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    22 Jul 2014
    Link to this post
    Hi all,

    @Paula

    You can use the .Do extension to add the UserId property:
    using (var fluent = App.WorkWith())
               {
                    fluent.Forms()
                       .Form("sf_YourForm")
                       .Entry()
                       .CreateNew(System.Guid.NewGuid())
                       .Do(a => a.UserId = theUserId)
                       .SetFieldValue("FormTextBox_C001", "Value1")
                     .SaveChanges();
                        }


    Regards,
    Ivan D. Dimitrov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  6. Tenet Health System
    Tenet Health System avatar
    4 posts
    Registered:
    12 Jun 2014
    26 Nov 2015
    Link to this post

    Hi,
    I am facing issue with "SetValue" method of FormEntry object, while I am trying to access "SetValue" method with FormEntry object. I am unable to get the same. Is there any sitefinity version issue or anything else. I am using Sitefinity V.8.0. Please find the attachment.

      entry.SetValue("FormTextBox_C001", "Angus");      //first name

    Thanks

  7. Raymond Dowe
    Raymond Dowe avatar
    37 posts
    Registered:
    10 Mar 2010
    26 Nov 2015 in reply to Tenet Health System
    Link to this post
    I think you're missing an import, "Telerik.Sitefinity.Model"
7 posts, 0 answered