multiple comment text areas

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.

Related posts

Leave a Reply

2 comments

  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.