Skip to content

[3.0] Give every poll choice the same id, whichever code built it - #9434

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/poll-option-ids
Open

[3.0] Give every poll choice the same id, whichever code built it#9434
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/poll-option-ids

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

Poll::format() handed out choice ids that already began with options-, and both
Post.template.php and Poll.template.php prefixed them again. The editing forms
therefore came out as:

<label for="options-options-3">Option 3</label>
<input type="text" name="options[options-3]" id="options-options-3">

There is a second builder. When the posting form comes back from a preview or a
validation error, Post.php fills Utils::$context['choices'] itself, and it has always
used the plain number. So the same form named its fields options[options-0] on first
load and options[0] after a preview, and the option the "Add option" script appends
matched neither.

On ?action=post;board=1;poll before:

first load after a preview
id options-options-0 options-0
name options[options-0] options[0]

Nothing actually broke: Poll::create() and PollEdit2 both run array_values() over
$_POST['options'] and renumber the choices by position, so the keys are thrown away.
It only made the markup unreadable and the two shapes impossible to reconcile.

Poll::format() now returns the number and leaves the prefix to whoever renders it,
which is what Post.php already assumed. The three places that label a vote button
gain the prefix, since those ids come from format() too — Display.template.php and
the two poll functions in ServerSideIncludes.php.

Checked on all four pages that render poll fields, before and after: the new-poll form,
the same form redisplayed after a preview, ?action=editpoll on an existing poll, and
the voting form on the topic. Every for= now resolves to an element, and the two
posting-form paths agree.

Issues References (Fixes|Related|Closes)

n/a

Poll::format() handed out ids that already began with "options-", and the
two editing templates prefixed them again, so the fields came out as
id="options-options-3" name="options[options-3]".

Post.php builds Utils::$context['choices'] itself when the posting form
comes back from a preview or an error, and it has always used the plain
number. So the same form named its fields options[options-0] on the way
in and options[0] on the way back, and the option the JS appends never
matched either.

Nothing broke, because both save paths run array_values() over the
submitted options and renumber them by position. It just made the markup
impossible to read.

Poll::format() now gives the number and leaves the prefix to whoever
renders it, which is what Post.php already assumed. Display.template.php
and the two SSI poll functions label the vote buttons, whose ids come
from format() as well, so they say options- themselves now.

Signed-off-by: Mathias Alberts <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@jdarwood007 jdarwood007 added this to the 3.0 Alpha 6 milestone Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants