Making Polls with Xforms in a usercontrol
by Rizo on dec.06, 2010, under Developing
XForm is a somewhat of a lazy way out. You know you should do the forms yourself but XForm is simple for the editors and also saves you a lot of job. Anyway, if you want to use XForm to make a poll, you’ll need to make a few adjustments.
First:
Create your new control and add an XForm property to the controls pagetype
Second:
Here you can take the template code from EPiServer to get the basic XForm functions.
Third:
Create your XForm in EPiServer and assign it to your page. Make sure to let anonymous post and also multiple times (Because all your users will be anonymous and you want anonymous to be able to vote more than once)
Fourth:
Create a cookie so people only vote once (they can delete their cookies and vote over and over so if you want a more secure way, go ahead and do it =D) and also so you can display the results insetad of the poll whenever they visit the page again.
The cookie could look something like this:
[sourcecode lang=”c#”]
private void SetCookie()
{
var cookie = new HttpCookie(”Poll-” + page.PageLink.ID);
cookie.Values.Add(”voted”, ”true”);
cookie.Expires = DateTime.Now.AddYears(24);
Response.Cookies.Add(cookie);
}
[/sourcecode]
and then you can check for the cookie and give the user different views depending if they voted or not. And that code could look something like this
[sourcecode lang=”c#”]
return;
var cookie = Request.Cookies.Get(”Poll-” + page.PageLink.ID);
if (cookie== null)
SetupForm();
else
SwitchView(null,null);
[/sourcecode]
Fifth:
If you’re using your XForm directly on a page, then you probably don’t need this step and you’re pretty much set. But if you want to use this as a usercontrol and add the poll with webparts or anything alike you’ll need to do this step.
The thing with EPiServers Statistics is that it will always fetch ”this.PageLink” so if you’re using this as a webpart/control it will try to get the currentpages xform property which will be null. Even if you load the XForm correctly and fetch it from your usercontrol path, the statistics won’t do it. In order to make Statistics work you’ll have to do this:
[sourcecode lang=”c#”]
Statistics.PageLink = page.PageLink;
Statistics.PageGuid = Form.PageGuid;
[/sourcecode]
Otherwise it will take the currentpage pagelink and pageguid. So basicly, you need to set up the Statistics just as you need to set up XForms.
Good luck!
16 Trackbacks / Pingbacks for this entry
mars 11th, 2023 on 06:56
Da ma cai
I found a great…
augusti 1st, 2023 on 00:09
4d lotto
I found a great…
oktober 7th, 2023 on 01:56
… [Trackback]
[…] Find More on that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
december 16th, 2023 on 18:34
… [Trackback]
[…] Here you will find 94568 more Information to that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
januari 22nd, 2024 on 00:47
… [Trackback]
[…] Find More on to that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
mars 3rd, 2024 on 02:43
… [Trackback]
[…] Read More on that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
mars 12th, 2024 on 00:59
… [Trackback]
[…] Here you can find 90416 more Info to that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
mars 28th, 2024 on 01:32
… [Trackback]
[…] Read More Information here on that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
april 16th, 2024 on 14:30
… [Trackback]
[…] Find More to that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
april 17th, 2024 on 20:56
… [Trackback]
[…] There you will find 87460 more Info on that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
april 17th, 2024 on 21:38
… [Trackback]
[…] Read More Information here on that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
maj 6th, 2024 on 01:01
… [Trackback]
[…] Here you will find 82286 additional Info to that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
maj 19th, 2024 on 01:48
… [Trackback]
[…] Find More on that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
juli 18th, 2024 on 04:02
… [Trackback]
[…] Here you can find 86401 more Information to that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
augusti 24th, 2024 on 02:01
… [Trackback]
[…] Read More here to that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]
september 29th, 2024 on 04:10
… [Trackback]
[…] Here you can find 42579 additional Information on that Topic: from-rizo.se/making-polls-with-xforms-in-a-usercontrol/ […]