Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add custom text fields to reply form


  • project_subdomain
    Participant

    @project_subdomain

    Hi all!

    I just cannot find a solution to add other custom text fields to the reply form.
    Looked at the plugin bbpress Reply Titles but this does not work – the title is not saved/displayed as content. Just find solutions for adding fields to the create new topic form.

    Is there anyone who as an idea how to achieve this?

Viewing 11 replies - 1 through 11 (of 11 total)

  • Robkk
    Moderator

    @robkk

    The information for adding new fields for topics could be helpful for adding fields to the reply form too. You may need to just change the word topic in any hooks used to reply, or just any word with topic with reply in the code.

    If you are just adding a simple text box for the reply form you can look over this example.

    add_action ( 'bbp_theme_before_reply_form_content', 'bbp_extra_reply_fields');
    function bbp_extra_reply_fields() {
       $waffle = get_post_meta( bbp_get_reply_id(), 'bbp_waffles', true);
       $pancake = get_post_meta( bbp_get_reply_id(), 'bbp_pancakes', true);
       echo '<fieldset class="bbp-form">';
       echo '<p><label for="bbp_waffles">Waffles</label><br>';
       echo "<input type='text' name='bbp_waffles' value='".$waffle."'></p>";
       echo '<p><label for="bbp_pancakes">Pancakes</label><br>';
       echo "<input type='text' name='bbp_pancakes' value='".$pancake."'></p>";
       echo '</fieldset>';
    }
    
    add_action ( 'bbp_new_reply', 'bbp_save_extra_fields', 10, 1 );
    add_action ( 'bbp_edit_reply', 'bbp_save_extra_fields', 10, 1 );
    
    function bbp_save_extra_fields($reply_id) {
      if (isset($_POST) && $_POST['bbp_waffles']!='')
        update_post_meta( $reply_id, 'bbp_waffles', $_POST['bbp_waffles'] );
      if (isset($_POST) && $_POST['bbp_pancakes']!='')
        update_post_meta( $reply_id, 'bbp_pancakes', $_POST['bbp_pancakes'] );
    }
    
    add_action('bbp_theme_after_reply_content', 'bbp_show_extra_fields');
    function bbp_show_extra_fields() {
      $reply_id = bbp_get_reply_id();
      $value1 = get_post_meta( $reply_id, 'bbp_waffles', true);
      $value2 = get_post_meta( $reply_id, 'bbp_pancakes', true);
      echo "Opinion on Waffles: ".$value1."<br>";
      echo "Opinion on Pancakes: ".$value2."<br>";
    }

    project_subdomain
    Participant

    @project_subdomain

    @Robkk:
    that’s great, thanks!
    How can I apply this to all topics for a specific forum?


    Robkk
    Moderator

    @robkk

    Not sure yet but maybe using a conditional bbp_is_single_forum('ID') with ID being the id of the forum.


    project_subdomain
    Participant

    @project_subdomain

    <?php if ( bbp_is_single_forum('ID') ) :?>
    <div>…</div>
    <php endif;?>

    does not work (no div at all at forum with this ID).


    Robkk
    Moderator

    @robkk

    could also just be bbp_is_forum( ID )


    project_subdomain
    Participant

    @project_subdomain

    @robkk I’m not sure why it’s not working proplerly (showing all divs in all forums). Could you give me a hint how the code has to look like, when I’d like to have
    forum id 1 echo div 1
    forum id 2 echo div 2
    forum id 3 echo div 3

    unforrtunately I’m not familiar with ternary operators which may be a option.


    Robkk
    Moderator

    @robkk

    Okay I tested it for awhile today, and I got it to work with this.

    function bbp_forum_thirteen() {
        $forum_id = bbp_get_forum_id();
        
        if ( $forum_id == 13 ) {
            echo '<p>THIS IS FORUM Thirteen</p>';
        }
    }    
        
    add_action( 'bbp_template_before_single_forum', 'bbp_forum_thirteen' );

    project_subdomain
    Participant

    @project_subdomain

    thanks, it’s working.
    How is that different and to achieve with a checkbox and a selection menu as custom fields?


    Robkk
    Moderator

    @robkk

    Whats different??

    If you want some specific custom fields that might be custom development for now.


    project_subdomain
    Participant

    @project_subdomain

    okay sorry, mistook it to be less different by saving the values. I try to get a better first overview of it.


    horayra7
    Participant

    @horayra7

    Thank you so much.
    I created a custom input field for the topic form.
    Everything is working properly, but inside the admin dashboard, when I try to update the custom input field value, it doesn’t work.

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Skip to toolbar