• I have been using the comment_form() tag in order to customise my comments form, however I cannot seem to modify the fields.

    Here is the code I have so far:

    <?php
    $fields =  array(
    	'author' => '<div class="field">' . '<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 . ' /></div>',
    	'email'  => '<div class="field"><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 . ' /></div>',
    	'url'    => '<div class="field"><label for="url">' . __( 'Website' ) . '</label>' .
    	            '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div>',
    ); ?>
    
    <?php comment_form('id_form=frm-comment&title_reply=Leave a Comment Yourself&fields=' . $fields); ?>

    The title and form ID change fine, but the fields do not. In fact, when I look at my form the only thing I see above the textarea element is just some text saying ‘Array’.

    Does anyone know what I am doing wrong?

    I think I need this line of code somewhere, but am unsure where to put it:
    apply_filters( 'comment_form_default_fields', $fields )

    I have tried it in both my comments.php and functions.php files but neither appear to work.

    If anyone has any advice that would be great 😀

Viewing 2 replies - 1 through 2 (of 2 total)
  • cscott5288

    (@cscott5288)

    I am running into this problem too.

    The tutorial for <?php comment_form(); ?> doesn’t make it clear what you have to do with $fields and apply_filters() to change the default HTML for the contact form:

    <?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>',
    ); ?>

    Any help?

    Thread Starter pealo86

    (@pealo86)

    Yes I fixed it in the end. The guy who wrote this tutorial cleared things up for me in the comments section:
    http://tinyurl.com/2csxmoo

    You need to call the comment form like this instead:
    comment_form(array('id_form' => 'frm-comment', 'title_reply' => 'Leave a Comment Yourself', 'fields' => $fields));

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trouble Changing Comment Form Fields’ is closed to new replies.