How can I make custom Wordpress comments form?


I have made following form, but it doesn't work because it doesn't send post id in post request.

$post = get_post($_GET['p']);

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" >
<label>Name : </label><br/>
<input name="author" id="author" type="text"/><br/>
<label>Comment : </label><br/>
<textarea name="comment" id="comment"></textarea><br/><br/>
<input name="submit"type="submit" id="submit"  value="Submit" />
<?php comment_id_fields(); ?>
<?php do_action('comment_form', $post->ID); ?>
9/1/2009 10:36:37 AM

Accepted Answer

Wordpress will drop any url parameters that it does not recognize. One way to add custom parameters in a url string is to use Add_Query_Args() function.

Take a look at Add_Query_Args Function Reference

This should solve your issue. Good luck.

9/1/2009 1:41:29 PM

With only a bit of tweaking was it possible to make it work.

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

<p><input type="text" name="author" id="author" value="" size="22" tabindex="1" /> 
<label for="author"><small>*</small></label></p> 

<p><input type="text" name="email" id="email" value="" size="22" tabindex="2"  /> 
<label for="email"><small>*</small></label></p> 

<p><textarea name="comment" id="comment" cols="48" rows="10" tabindex="4" onFocus="clearText(this)" onBlur="clearText(this)" ></textarea></p> 

<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit" /> 
<?php comment_id_fields(); ?>

<?php do_action('comment_form', $post->ID); ?>

Above code works (for me). Basically, you were missing an id on the form. WP apparently uses that id as part of the validation process.

So, to make it work, add id="commentform" to your form-tag, and it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow