User ID as Hidden Field of Custom Form
What is the best way once a visitor has logged on to the web site to have them fill out a custom form but associate that response with that user? I'd like to have users fill out surveys once they log on the my web site.
Thanks,
Matt
Hello Matt,
This can be done with the forms control. You may need to modify the log in widget(you can get its template from Sitefinity SDK) to redirect to a page where the survey is placed. By default Forms get the user ID, but not the user name. You can follow this forum thread if you want to search users by the ID and apply this to suit your needs. Also when you submit a response this created FormEntry object which has a property - UserId. This is the ID of the user submitted the form. 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)
Below is a sample code that shows getting form results filtered by user ID
var formsManager = FormsManager.GetManager();
string
entryTypeName = String.Format(
"0.1"
,
"Telerik.Sitefinity.DynamicTypes.Model"
,
"sf_yourformname"
);
var itemType = formsManager.GetEntryType(entryTypeName);
var userID = SecurityManager.GetCurrentUserId();
var fakeID =
new
Guid(
"4B15FA4B-6C36-4CE5-A56D-9FDFB6E541DF"
);
var filter =
"UserId =="
+ fakeID +
""
;
int
? totalCount = 0;
IEnumerable items =
null
;
try
items = formsManager.GetFormEntries(itemType, filter,
"Title ASC"
, 0, 100,
ref
totalCount);
catch