Create form responses programmatically?

Posted by Community Admin on 03-Aug-2018 15:15

Create form responses programmatically?

All Replies

Posted by Community Admin on 08-Jan-2013 00:00

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.

Posted by Community Admin on 11-Jan-2013 00:00

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

Posted by Community Admin on 14-Jul-2014 00:00

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

Posted by Community Admin on 17-Jul-2014 00:00

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

Posted by Community Admin on 22-Jul-2014 00:00

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
 

Posted by Community Admin on 26-Nov-2015 00:00

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

Posted by Community Admin on 26-Nov-2015 00:00

I think you're missing an import, "Telerik.Sitefinity.Model"

This thread is closed