WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 7 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:

Description

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:
http://www.optimisationbeacon.com/analytics/track-blog-comments-in-google-analytics/
http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html

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>
http://codex.wordpress.org/Function_Reference/comment_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 3 years ago.
20302-2.diff (2.3 KB) - added by jkudish 3 years ago.
initial path had syntax errors, now fixed

Download all attachments as: .zip

Change History (6)

comment:1 @psbook3 years ago

  • Version set to 3.3.1

comment:2 @jkudish3 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.

@jkudish3 years ago

@jkudish3 years ago

initial path had syntax errors, now fixed

comment:3 @SergeyBiryukov3 years ago

  • Version changed from 3.4 to 3.3.1

Version field indicates when the enhancement was initially suggested.

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

comment:4 @chriscct77 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.