Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Can you convert my comments form to comment_form arrays? WordPress

  • SOLVED

We would like the below comment form fields to be converted into comment_form arrays. In your response please provide a complete <?php to ?> snippet.

Arrays that should be filled in are:
comment_field
must_log_in
logged_in_as
comment_notes_before
comment_notes_after'
id_form
id_submit
title_reply
title_reply_to
cancel_reply_link
label_submit
* am I missing any?
** If an array would have no data please place ". . ." as a place holder.

<section id="leaveresponse">
<h3 class="cssfonts--17">Leave a Response</h3>

<?php if (get_option('comment_registration') && !$user_ID) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>
<?php else : ?>

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

<?php if ($user_ID) : ?>
<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Log out &raquo;</a></p>
<?php else : ?>

<div id="authorData">
<label for="author">Name <?php if ($req) echo "(required)"; ?></label>
<input type="name" name="author" id="author" class="commentmeta-textbox cssfonts--16 textbox-grey" value="<?php echo $comment_author; ?>" size="55" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?>>
<div class="clear"></div>

<label for="email">Email (will not be published) <?php if ($req) echo "(required)"; ?></label>
<input type="email" name="email" id="email" class="commentmeta-textbox cssfonts--16 textbox-grey" value="<?php echo $comment_author_email; ?>" size="55" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?>>
<div class="clear"></div>

<label for="url">Website</label>
<input type="url" name="url" id="url" class="commentmeta-textbox cssfonts--16 textbox-grey" value="<?php echo $comment_author_url; ?>" size="55" tabindex="3">
<div class="clear"></div>
</div>

<?php endif; ?>

<!-- p>Allowed <abbr title="HyperText Markup Language">HTML:</abbr> tags: <code><?php echo allowed_tags(); ?>
</p -->
<label for="comment">Comment</label>
<textarea name="comment" id="comment" class="cssfonts--18 textbox-grey" cols="70" rows="4" tabindex="4"></textarea>
<div class="clear"></div>
<button class="btn btn-large" type="submit" name="submit"><span><span>Submit Comment</span></span></button>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>">
<?php do_action('comment_form', $post->ID); ?>

</form>
<?php endif; ?>

</section>
</code>

Answers (1)

2010-09-29

Denzel Chia answers:

Hi,

I had coded you a WordPress 3.0 comment form based on the above codes you posted.
This form uses the function comment_form().
You can further customization by adding into the $arguments array.
You can refer to http://codex.wordpress.org/Function_Reference/comment_form
or http://ottopress.com/2010/wordpress-3-0-theme-tip-the-comment-form/
for customization examples.

Or simply drop me a reply, I will add in your customization.


<section id="leaveresponse">

<?php if (get_option('comment_registration') && !$user_ID) : ?>

<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>

<?php else : ?>

<?php
$arguments = array(
'id_form' => 'commentform',
'id_submit' => 'submit',
'title_reply' => __( '<h3 class="cssfonts--17">Leave a Response</h3>' ),
'title_reply_to' => __( 'Leave a Reply to %s' ),
'cancel_reply_link' => __( 'Cancel reply' ),
'label_submit' => __( 'Post Comment' ),
);
?>
<?php comment_form($arguments); ?>

<?php endif; ?>

</section>



Thanks.


Matt Taylor comments:

Denzel,

I am familiar with Otto's writeup and [[LINK href="http://bluemushrooms.com/wordpress-adding-comment_form-theme/"]]Sapphire's response[[/LINK]]. I am looking for more of a finished product, I just don't have the time to do this myself. If you can do the customization we can wrap this WPQuestion up as answered. :)


Denzel Chia comments:

Yes,

Just use the above code and tell me what you need further.

Thanks.


Matt Taylor comments:

We need to add html to the field inputs themselves for things such as classes, aria-required="true", and to control input types such as email.

So the fields we need to add code to are: name, email, website, and comment.


Denzel Chia comments:

Ok,

The below codes adds in the fields name, email, website in the $fields array.
Just change the class="comment-form-author" to what you need.
For the comment textarea just change class="comment-form-comment"to what you need.
And any other HTML in it that you want to change into.


<section id="leaveresponse">

<?php if (get_option('comment_registration') && !$user_ID) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>

<?php else : ?>

<?php

$fields = array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
);

?>

<?php

$arguments = array(
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
'id_form' => 'commentform',
'id_submit' => 'submit',
'title_reply' => __( '<h3 class="cssfonts--17">Leave a Response</h3>' ),
'title_reply_to' => __( 'Leave a Reply to %s' ),
'cancel_reply_link' => __( 'Cancel reply' ),
'label_submit' => __( 'Post Comment' ),
);

?>
<?php comment_form($arguments); ?>
<?php endif; ?>
</section>




Thanks.