2

I need to create a user comment form with three text areas and then display them in comments. I don't know where to start - cannot find any plugin but would like to code it anyway. Any pointers much appreciated.

2 Answers 2

1

To add new fields, simply append them to the default fields with a plugin.

<?php
defined( 'ABSPATH' ) AND exit;
/* Plugin Name: (#85059) Append form fields to comment form */

add_filter( 'comment_form_default_fields', 'wpse85059_comment_form_extd', 100 );
function wpse85059_comment_form_extd( $fields )
{
    // Append new fields …
    if ( 'comment_form_default_fields' === current_filter() )
    {
        foreach ( array( 'ctax_1', 'ctax_2', 'ctax_3' ) as $ctax )
            $fields[] = "<input value='{$ctax}' name='{$ctax}' />";
        return $fields;
    }
}

Then there's also the possibility to use comment meta data. More about it can be read in the Codex.

To attach the meta data, you can hook into an action:

add_filter( 'comment_id_fields', 'wpse85059_comment_meta_fields', 10, 3 );
function wpse85059_comment_meta_fields( $result, $id, $replytoid )
{
    add_action ( 'comment_post', 'wpse85059_comment_meta', 1 );

    foreach ( array( 'ctax_1', 'ctax_2', 'ctax_3' ) as $ctax )
        $result .= "<input value='{$ctax}' name='{$ctax}' />";

    return $result;
}
function wpse85059_comment_meta( $comment_id )
{
    // Only run once
    remove_filter( current_filter(), __FUNCTION__ );

    foreach ( array( 'ctax_1', 'ctax_2', 'ctax_3' ) as $ctax )
        add_comment_meta(
             $comment_id
            ,$ctax
            ,$_POST[ $ctax ]
            ,true
        );
}

Note: This is not tested, but should give you a starting point.

1
  • @user26166 Feel free to edit my answer with a full & working solution. I'll approve it.
    – kaiser
    Feb 8, 2013 at 13:24
0

3 textares for what purpose? or you meant 2 input´s and 1 texarea plus 1 input button? i would start reading at http://codex.wordpress.org/Function_Reference/comment_form

1
  • 3 textareas to catagorize comments for a review system, thanks. Feb 8, 2013 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.