Entries from Forms
I am wanting to create a custom control that displays collective results of the entries from a specific form built in the Forms Module. Do you have an example of how to retrieve this data? I have found the FormManager and FormsManager, but I do not see a method that gets entries for a specific form.
Thanks!
Alex Lorenz
Indianapolis Motor Speedway | INDYCAR
Hi Alex,
To get the response of a form you can use
public IEnumerable GetFormEntries(Type entryType, string filter, string orderBy, int skip, int take, ref int? count)
var formsManager = FormsManager.GetManager();
stringentryTypeName = String.Format(
"0.1"
, "
Telerik.Sitefinity.DynamicTypes.Model
", "
yourformname");
var itemType = formsManager.GetEntryType(entryTypeName);
int
? totalCount = 0;
IEnumerable items =
null
;
try
items = formsManager.GetFormEntries(itemType,
string
.Empty,
string
.Empty, 0, 0, reftotalCount);
This gets the entries, but is there then a method to get the values from that entry?
Thanks!
Alex Lorenz
Hi Alex,
GetFormEntries returns list of the FormEntry which you can use to get the values.
Regards,
Ivan Dimitrov
the Telerik team
I am able to get values of the entry, such as SubmittedOn, UserID, IpAddress, but is there another method to get the actual response. For example, we have a form out there that has a single multiple choice form widget and I want all the values from that single multiple choice question. Am I missing something to get actual form question data from the custom table that is built on the fly?
Here is the code I am using, including what you provided:
var formsManager = FormsManager.GetManager();
string
entryTypeName = String.Format(
"0.1"
,
"Telerik.Sitefinity.DynamicTypes.Model"
,
"sf_motegireplacementpoll"
);
var itemType = formsManager.GetEntryType(entryTypeName);
int
? totalCount = 0;
IEnumerable items =
null
;
try
items = formsManager.GetFormEntries(itemType,
string
.Empty,
string
.Empty, 0, 0,
ref
totalCount);
foreach
(FormEntry item
in
items)
//var entry = formsManager.GetFormEntry(entryTypeName, item.Id);
this
.results.Text += item.UserId;
catch
Hi Alex,
The code should return all fields. Please take a look at attached short video. Here is the code that was used during the video
void
button1_Click(
object
sender, EventArgs e)
var formsManager = FormsManager.GetManager();
string
entryTypeName = String.Format(
"0.1"
,
"Telerik.Sitefinity.DynamicTypes.Model"
,
"sf_yourformname"
);
var itemType = formsManager.GetEntryType(entryTypeName);
int
? totalCount = 0;
IEnumerable items =
null
;
try
items = formsManager.GetFormEntries(itemType,
null
,
"Title ASC"
, 0, 100,
ref
totalCount);
catch
MyResumesList model = new MyResumesList();
//model.MyResumes = GetResumes();
User user = userManager.GetUser(System.Web.HttpContext.Current.User.Identity.Name);
List<MyResumesListModel> objMyResumesList = new List<MyResumesListModel>();
//Get the Form by Name
var form = formsManager.GetForms().Where(f => f.Name == "formName").SingleOrDefault();
//Get the FormEntries for that Form
var records = formsManager.GetFormEntries(form).Where(x => x.UserId==user.Id).ToList();
// Loop through all the response records for this form
foreach (FormEntry record in records)
//Use GetValue() to obtain the Field value
var FileName = record.GetValue("FileName");
var DateUpdated = record.GetValue("DateUpdated");
var Id = record.GetValue("Id");
objMyResumesList.Add(new MyResumesListModel ResumeTitle = FileName.ToString(), DateUpdated = DateUpdated.ToString(), Id = Id.ToString() );
return View("Default", objMyResumesList);