Make WordPress Core

Opened 4 years ago

Last modified 13 months ago

#20302 new enhancement

Allow comment_form() to add attributes to <form> tag

Reported by: psbook Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.3.1
Component: Comments Keywords: needs-refresh
Focuses: Cc:


The standard method to allow Google Analytics to track comment submissions as a 'goal' is to add a piece of JavaScript code wrapped in an 'onsumbit' attribute:

We want something like the following:

<form action="http://www.example.com/wp-comments-post.php" method="post" id="commentform" onsubmit="_gaq.push(['_trackEvent', 'Comments', 'Submit', 'POST TITLE']);">

However the current arguments submitted to comment_form() do not provide for adding attributes to <form>

I was forced to perform a workaround in which the onsubmit code was inserted by JavaScript on the fly at runtime.

So this is request to alter comment_form() such that arguments accepted provide for 'onsubmit' or other custom attributes to be appended on the <form> tag.

Attachments (2)

20302-1.diff (2.3 KB) - added by jkudish 4 years ago.
20302-2.diff (2.3 KB) - added by jkudish 4 years ago.
initial path had syntax errors, now fixed

Download all attachments as: .zip

Change History (6)

#1 @psbook
4 years ago

  • Version set to 3.3.1

#2 @jkudish
4 years ago

  • Cc joachim.kudish@… added
  • Keywords has-patch needs-testing added
  • Version changed from 3.3.1 to 3.4

The proposed/attached patch adds a 'form_attributes' argument to the $args for comment_form, it also adds 2 new filters, one for the attributes (which are passed as a key/value array) and one for the entire form element as it gets output.

4 years ago

4 years ago

initial path had syntax errors, now fixed

#3 @SergeyBiryukov
4 years ago

  • Version changed from 3.4 to 3.3.1

Version field indicates when the enhancement was initially suggested.

Last edited 4 years ago by SergeyBiryukov (previous) (diff)

#4 @chriscct7
13 months ago

  • Keywords needs-refresh added; has-patch needs-testing removed

Needs a refresh because of the HTML class added in #23851

Note: See TracTickets for help on using tickets.