创建和管理投票

:bookmark: This guide explains how to create polls in Discourse to gather votes from users on any topic.

:person_raising_hand: Required user level: All users

:information_source: By default, polls are enabled in Discourse and users of trust level 1 or above are allowed to create them. Site admins can adjust who can create polls via the poll create allowed groups site setting and disable polls using the poll enabled site setting.

Creating a poll from the toolbar

The easiest way to create a poll is to use the poll builder. The poll builder can be accessed from the :gear: menu in the composer, and allows you to make a poll without needing to know the exact syntax.

To show advanced options press the :gear: icon. This will show you different poll options such as if the poll auto closes, set groups allowed to vote, choose bar or pie, etc.

Poll options

Poll type:

  • Single Choice: Default poll type. Users can select a single choice from the poll
  • Multiple Choice: Users can select multiple choices from the poll.
    • The poll creator must also define the minimum and maximum number of choices a user can make. By default the minimum will be 1, and the maximum will be the number of poll choices.
  • Number Rating: Users can select a single number.
    • The poll creator must also define the min, max and step for the number rating. For example, if the min is 2, the max is 10, and the step is 2, the options will be 2, 4, 6, 8, and 10.

Results:

  • Always visible: Default poll results. Users can always see the results of the poll, regardless of if they’ve voted.
  • Only after voting: Users must vote before they can see the results of the poll.
  • When the poll is closed: Poll results will only be revealed once the poll is closed.
  • Staff only: Only site staff will be able to see the poll results.

Allowed groups:

Allows the poll creator to limit which groups can participate in the poll. Users not in the listed groups will be able to view the poll, but not vote. Default is all users can participate, no group limitation.

Chart type:

For Single or Multiple Choice polls, choose whether to display the result in a bar graph or pie chart.

Show who voted:

Enabled by default, this allows those who can view poll results to also view the specific choices of each poll user. (Bar Chart type only)

Automatically close poll:

Allows the poll creator to set a date/time for the poll to close automatically. Unlike manually closed polls, auto-closed polls cannot be re-opened.

Including images

Polls can even include images! After using the poll builder to insert the poll, images can be uploaded to the post and manually added to the poll. Uploaded images should be small, or adjusted to display at a lower percentage:

[poll type=regular]
* ![image|690x458,25%](upload://2u570X7kQiPJQaJD1Bd8MLDHDNB.jpeg)
* ![image|690x334,25%](upload://35fmeFw8RMywSxIc4lbCb8UHPaT.jpg)
* ![image|690x499,25%](upload://xSDkRwmuj1pNc2QXKzthfXRlwsX.jpg)
[/poll]
[poll type=regular]
* Cat: a small domesticated carnivorous mammal with soft fur, a short snout, and retractile claws.
![image|690x458,25%](upload://2u570X7kQiPJQaJD1Bd8MLDHDNB.jpeg)
* Dog: a domesticated carnivorous mammal that typically has a long snout, an acute sense of smell, and a barking, howling, or whining voice.
![image|690x334,25%](upload://35fmeFw8RMywSxIc4lbCb8UHPaT.jpg)
* Fish: a limbless cold-blooded vertebrate animal with gills and fins and living wholly in water.
![image|690x499,25%](upload://xSDkRwmuj1pNc2QXKzthfXRlwsX.jpg)
[/poll]
  • Cat: a small domesticated carnivorous mammal with soft fur, a short snout, and retractile claws.
  • Dog: a domesticated carnivorous mammal that typically has a long snout, an acute sense of smell, and a barking, howling, or whining voice.
  • Fish: a limbless cold-blooded vertebrate animal with gills and fins and living wholly in water.
0 voters

Including relative dates

Polls can also include relative dates! In a similar way to adding images, after using the poll builder to insert the poll you can insert dates into the poll options via the “Insert date / time” composer button:

[poll type=regular]
* [date=2019-10-13 timezone="Europe/Paris"]
* [date=2019-10-12 timezone="Europe/Paris"]
* [date=2019-10-11 timezone="Europe/Paris"]
[/poll]
  • 2019-10-12T22:00:00Z
  • 2019-10-11T22:00:00Z
  • 2019-10-10T22:00:00Z
0 voters

Multiple polls in a post

If multiple polls are used in a single post (like this one!) each poll will need a unique name or they will not work. When using the poll builder each extra poll will be numbered sequentially, but you can also do this manually by adding name="poll_name" as a parameter:

[poll name="poll_1"]
1. option one
2. option two
3. option three
[/poll]

[poll name="poll_3" type=multiple min=2 max=3]
- option one
- option two
- option three
- option four
[/poll]

[poll name="dave" type=number min=2 max=10 step=2]
[/poll]

Manually creating a poll

While the poll builder is the easiest option, it is also possible to manually create and edit polls within the composer itself.

To create a simple poll, surround a markdown list with [poll] and [/poll]:

[poll]
* option one
* option two
* option three
[/poll]

:information_source: Any markdown list will work, including using hyphens - or numbers instead of asterisks *.

This will create the following result:

  1. option one
  2. option two
  3. option three
0 voters

To manually create more complex polls, additional parameters can be added to the poll tag. For instance:

[poll type=multiple results=on_vote min=1 max=2 public=true chartType=pie groups=trust_level_1 close=3024-12-31T00:00:00.000Z]
# Do you like polls?
* Yes
* No
* Maybe
[/poll]
Do you like polls?
  • Yes
  • No
  • Maybe
0 voters

(Though not all options will make sense for all polls :slight_smile:)

Using the poll builder is a great way to find out the format of these additional parameters for later use.

FAQs

Can anyone vote in a poll?

Even with no group voting restrictions on the poll itself, users must be able to reply to the topic where the poll is created in order to participate. Users with see only permissions will not be able to vote.

Can polls be edited?

All votes are cleared when a poll is edited, to ensure the poll creator can’t change the choices a user voted for. As such, by default polls can only be edited for a grace period of 5 minutes after being created.

:exclamation: Votes cannot be recovered once a poll is edited and the votes are cleared

Can I export poll data for further analysis?

Staff can use the Discourse Data Explorer to export poll data as a csv, which can be imported into the data analysis program of their choice.

Last edited by @hugh 2024-07-29T10:05:00Z

Last checked by @hugh 2024-07-02T09:50:57Z

Check documentPerform check on document:
62 个赞

这可能看起来像一个新手问题,但我确实有一个疑问。

假设我创建了一个投票,其中我设置了投票结果在投票后立即可见。然后我意识到我的错误,我本应该在投票结束后才显示结果。那么,有没有办法编辑当前的投票,以便将该投票的可见性从“始终可见”更改为“投票结束后可见”,这是在构建投票设置中可从齿轮图标访问的选项?

或者,我必须删除这个投票,然后开始一个新的投票,并选择“投票结束后可见”的投票可见性设置?

我还附上了截图。

请提供建议。

如果此帖子不适合此主题,我请求版主/管理员将其移至适当的部分。

1 个赞

您可以在不删除投票的情况下进行更改。编辑帖子时,您的投票将以类似 [poll type=regular results=on_vote public=true chartType=bar] 的内容开始;您可以将“results”参数编辑为 results=on_close
不过,如果我没记错的话,编辑投票时,所有投票都会被删除,但至少您不必重新创建它。

3 个赞

确实如此。

对我来说,如果有一个选项可以重置投票,而不是被“强制”重置,会更有意义——尤其是对于这种小的调整。

我过去曾为这些类型的更改(以避免编辑触发重置)入侵过数据库,但这有点脆弱。

4 个赞

这很有帮助。

如果我告诉你们,当创建投票的管理员编辑了用于投票的主题时,主题编辑次数反而会减少而不是增加,你们会作何推断?

我的推断是,投票被删除了,然后重新开始了一个新的投票。这对投票者来说可以解释为什么主题编辑次数会减少。

例如:
用户第一次来到投票页面,投票设置是“始终可见”。该投票的主题编辑次数是 4。

当管理员被指出投票设置被设为“始终可见”时,用户随后看到投票的投票设置被改为“投票后可见”。然而,主题编辑次数却变成了 3。所以,主题编辑次数非但没有增加,反而减少了。

我的想法是,管理员删除了之前的投票,然后重新开始了一个新的投票。

1 个赞

是否可以将此文档更新为包含排序选择投票?特别是,回合是如何以及何时增加的。
提前感谢各位!

5 个赞

说得有理 @meave

我是排序选择投票的作者,这确实是个失误。

我没有 OP 的编辑权限。非常乐意有人复制此内容并按他们认为合适的方式进行格式化,或者如果转换为 Wiki,我很乐意做出贡献:

目前它的工作方式与此处描述的完全一样,这是经典的即时决选投票:

(我的投票插件分支实际上包含该示例作为单元测试!)

过程如下:

每位选民提交一份候选人排序列表。在每一轮中,我们只考虑排名第一的候选人(并关注潜在的获胜者和最差的失败者)。

  1. 计算每位候选人的第一名选票
  2. 找出得票最多的候选人
  3. 检查是否存在明确的、单一的多数,如果找到则返回获胜者(无需更多回合,停止)

如果没有:

  1. 找出得票最少的候选人
  2. 从所有选票中移除得票最少的候选人

如果选票现在都为空

  1. 报告刚刚被移除的候选人的平局(无需更多回合,停止)

否则

  1. 将所有选票向上移动,以便当第一名被某个选民的失败者占据时,第二名候选人成为他们的第一选择。

然后回合继续,直到找到多数或平局。

6 个赞

感谢 @merefield
这正是我需要的!

3 个赞

是否可以导出不同频道的每个投票结果以用于报告?

1 个赞

您可以使用数据浏览器来完成此操作。我问了 AI
“是否可以导出不同频道中每个投票的结果以用于数据浏览器报告目的?”它给出了这个查询:

SELECT  
    p.topic_id, 
    p.name AS poll_name,
    o.id AS option_id, 
    o.html AS option_text, 
    COUNT(v.id) AS vote_count
FROM polls p
JOIN poll_options o ON p.id = o.poll_id
LEFT JOIN poll_votes v ON o.id = v.poll_option_id
GROUP BY p.topic_id, p.name, o.id, o.html
ORDER BY p.topic_id, p.name, o.id;

看起来它可能会起作用?

1 个赞

您好 @pfaffman

非常感谢您的快速回复和帮助!

我将在下周某个时候尝试一下,但最有可能在假期后才能尝试。

一旦能够尝试,我会带回反馈。

此外,再次非常感谢!

1 个赞

您好,我有一个关于投票的问题。

是否可以使用 HTML 或 CSS 使其看起来比标准外观更美观?

提前致谢。

您是否在浏览器的检查器中尝试过?(右键单击并检查)如果您可以在那里做到,那么是的。

但是,Polls 使用 Chart.js,所以有很多矢量的东西。

这真的取决于您想改变什么。

3 个赞

这是一个排名投票。当文本过长时,用于做出选择的按钮应位于文本的左侧。现在文本位于按钮下方,我希望文本完全靠右,按钮与左侧文本对齐。

大家好,

有人知道是否可以以某种方式在投票中包含文本输入吗?例如,让投票者说明选择特定选项的原因?

1 个赞

“在下面评论”?

除了在主题中评论之外,不可以。

1 个赞

我明白了。谢谢你,@merefield,我正试图得到一份书面反馈,可以与投票结果一起导出。

1 个赞


为什么投票没有显示在动态消息中?只有点击后才显示。

2 个赞

啊,我认为这是投票/主题摘录的限制。我认为目前无法在主主题空间之外显示它们。

3 个赞

感谢你的回答!

3 个赞