Opened 14 months ago
Last modified 14 months ago
#20302 new enhancement
Allow comment_form() to add attributes to <form> tag
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Comments | Version: | 3.3.1 |
| Severity: | normal | Keywords: | has-patch needs-testing |
| Cc: | joachim.kudish@… |
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)
Change History (5)
- Cc joachim.kudish@… added
- Keywords has-patch needs-testing added
- Version changed from 3.3.1 to 3.4
comment:3
SergeyBiryukov — 14 months ago
- Version changed from 3.4 to 3.3.1
Version field indicates when the enhancement was initially suggested.

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.