[wp-hackers] Idea for comments.php

Owen Winkler ringmaster at midnightcircus.com
Mon Oct 2 23:15:16 GMT 2006


Roland Haeder wrote:
>> Why not put the JavaScript in the header, via the wp_head action hook?
> The reason for this is that some want to pre-check via this code:
> 
> <!-- Somewhere in the a-tag: //-->
> onSubmit="return submitHook();" onReset="return resetHook();"

Include a reference to prototype or a prototype-like library in wp_head, 
and add an event observer:

Event.observe(window, 'load', function(e) {
$('commentform').appendChild(Builder.node("input", {
type: "hidden", name: "myfield", value: 'foo'});
// Or whatever
});

> Now we "just" need to add something like this inside of the <form></form> 
> comtainer and everyone is happy:
> 
> <?php wp_javascript(); ?>

Dumping javascript into the page to run as it's downloaded might not be 
the best idea, especially since I've provided an example of how to do it 
well, but here you go:


add_action('comment_form', 'my_php_function', 1);

function my_php_function($postid) {
	echo "Post ID: {$postid}";
}


This hook is already in the default theme's template code.  See 
comments.php.

Owen



More information about the wp-hackers mailing list