Skip to:
Content
Pages
Categories
Search
Top
Bottom

Using custom placeholder text in reply form (bbp_reply_content)


  • MarximusMG
    Participant

    @marximusmg

    I’m trying to find the file where I can edit the input field for the reply form. Any help is appreciated.

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

  • Robkk
    Moderator

    @robkk

    you will most likely need a filter to do this, but this is kind of not really necessary so all i can say is dont really worry about this.


    MarximusMG
    Participant

    @marximusmg

    Yeah, it’s not necessary, but I’d like to hide the “Reply To: ….” label above this field so clean up the look of it, and just wanted to be able to have the text “Reply” as a placeholder in this field to prompt the user.

    I just can’t for the life of me find the reference to this field in form-reply.php. I’m able to see where I could add the placeholder for the form when editing a reply, but not in the standard reply form.


    Robkk
    Moderator

    @robkk

    i can tell you its not in form-reply.php , its most likey in a template.php file.

    but hey if you can find a wordpress theme that has this , ILL try to find a way to get this functionality.


    Robin W
    Moderator

    @robin-w

    Apologioes if I’m being thick, but line 29 of bbpress/templates/default/bbpress/form-reply.php says

    <legend><?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?></legend>
    

    Is that not the line you want to get rid of/change?


    MarximusMG
    Participant

    @marximusmg

    @robin-w no, I’m able to hide that component just fine, but I’m trying to insert a text placeholder within the input field of the form itself.


    @robkk
    I’ve seen it in multiple forums, but most recently I saw it being used (again on) http://www.highexistence.com/topic/philosophical-movies-i-want-them/


    Robkk
    Moderator

    @robkk

    @marximusmg yeah i know you got this whole topics idea from high existence

    im just saying if you find a wordpress theme that is compatible with bbpress either on the wordpress free theme repository or on like themeforest and it has a placeholder in the reply area tell me.

    if you find it before me then update this topic with the name of the theme.


    Robin W
    Moderator

    @robin-w

    this is interesting…

    Your link

    Philosophical Movies – I want them

    only shows that the coder has changed the lines
    ‘You must be logged in to reply to this topic’
    in
    form-reply.php

    form-reply.php is called by

    content.single.topic.php

    on line 44.

    Now you could change line 44, BUT and here’s the issue, we are talking php, which is a pre-processor, so by the time it creates the page, you can’t have a conditional and it has processed, so a ‘click to do reply form’ from this .php is not simple.

    There’s loads on the net about this eg

    http://stackoverflow.com/questions/20738329/how-to-call-a-php-function-on-the-click-of-a-button

    google something like php click link to do function

    All of it talks about using ajax – soemting that is entirely alien to me, and I can’t find an example to use, they all lose me in jargon I don’t know.

    It’s definitely do-able, but I don’t know how !!


    Robkk
    Moderator

    @robkk

    @robin-w

    idk what your talking about here when its all about a placeholder, that only a user can see if there logged in, you might be over-thinking it when you say this or you reply your information to the wrong topic that this user has.

    Maybe this??

    Customizing "Reply To Topic" Area


    @marximusmg

    i actually got a placeholder in my reply area , but you will lose the quick tag toolbar by doing it this way.

    in form-reply.php replace

    <?php do_action( 'bbp_theme_before_reply_form_content' ); ?>
    
    					<?php bbp_the_content( array( 'context' => 'reply' ) ); ?>
    
    					<?php do_action( 'bbp_theme_after_reply_form_content' ); ?>

    with this

    <?php do_action( 'bbp_theme_before_reply_form_content' ); ?>
    
    					<textarea placeholder="Reply..." id="bbp_reply_content" tabindex="104" name="bbp_reply_content"></textarea>
    
    					<?php do_action( 'bbp_theme_after_reply_form_content' ); ?>

    heres a snippet of form-reply.php with the code inserted

    <div class="bbp-template-notice">
    						<p><?php _e( 'Your account has the ability to post unrestricted HTML content.', 'bbpress' ); ?></p>
    					</div>
    
    				<?php endif; ?>
    
    				<?php do_action( 'bbp_template_notices' ); ?>
    
    				<div>
    
    					<?php bbp_get_template_part( 'form', 'anonymous' ); ?>
    
    					<?php do_action( 'bbp_theme_before_reply_form_content' ); ?>
    
    					<textarea placeholder="Reply..." id="bbp_reply_content" tabindex="104" name="bbp_reply_content"></textarea>
    
    					<?php do_action( 'bbp_theme_after_reply_form_content' ); ?>
    
    					<?php if ( ! ( bbp_use_wp_editor() || current_user_can( 'unfiltered_html' ) ) ) : ?>
    
    						<p class="form-allowed-tags">
    							<label><?php _e( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:','bbpress' ); ?></label><br />
    							<code><?php bbp_allowed_tags(); ?></code>
    						</p>

    Robin W
    Moderator

    @robin-w

    sorry, I completely misread what marximusmg was asking, and thought he wanted to replace the whole reply form area with a button that would fire up a reply area.

    Now I understand what marximusmg is after, the solution is

    add_filter( 'bbp_get_the_content', 'amend_reply', 10, 3);
    
    Function amend_reply ($output, $args, $post_content) {
    if ($args['context'] == 'reply' && $post_content == '') $output=str_replace('></textarea>', 'placeholder="Reply..." ></textarea>',$output) ;
    return $output ;
    }

    Robkk
    Moderator

    @robkk

    @marximusmg use robins code, his version is a better way


    crystalleeanne
    Participant

    @crystalleeanne

    Okay, this topic gets me part of the way there…
    Can someone please help me figure out how to modify this filter code to create placeholder text for the bbPress login form widget? (Username and Password fields).


    Robin W
    Moderator

    @robin-w

    @crystalleeanne that might be difficult, as the textarea is only acted on upon submitting the form.

    Can you explain what you are trying to achieve


    crystalleeanne
    Participant

    @crystalleeanne

    For some reason the forum wiped out my reply so here it is again:

    I’m trying to get the bbPress login form to use input placeholder text so I can eliminate the old style labels that appear above the fields:

    On the left, what I’m trying to achieve and how my theme styles forms (placeholder text set for input fields rather than text above each field).

    On the right, the bbPress login widget styled similarly to the form on the right… just need to figure out how to write a function to set the placeholder text for these fields…hopefully.

    http://tinypic.com/r/zj6whw/8


    Robin W
    Moderator

    @robin-w

    ok, no easy filters, are you ok at coding, ie getting some code and amending it. If so i’ll come back with more info


    crystalleeanne
    Participant

    @crystalleeanne

    I’m okay at coding, I can usually figure out what needs to be done if I have something to compare it to. At this point I’m happy to try anything. I’m also using a backed up child theme, so I can make theme edits (if needed) without harming anything if I screw up it! lol 😉


    Robin W
    Moderator

    @robin-w

    It was quicker to code it than describe it.

    Basically I’ve created a new widget called (rew) Login Widget

    Copy all the below into your functions file

    You’ll see that all it required was taking out the label, and putting ‘placeholder’ into the input line

    I even changed lost password into forgot your password !

    The go into widgets and you’ll see the new widget (rew) Login Widget

    enjoy !

    class Rew_Login_Widget extends WP_Widget {
    
    	/**
    	 * bbPress Login Widget
    	 *
    	 * Registers the login widget
    	 *
    	 * @since bbPress (r2827)
    	 *
    	 * @uses apply_filters() Calls 'bbp_login_widget_options' with the
    	 *                        widget options
    	 */
    	public function __construct() {
    		$widget_ops = apply_filters( 'rew_login_widget_options', array(
    			'classname'   => 'bbp_widget_login',
    			'description' => __( 'A simple login form with optional links to sign-up and lost password pages.', 'bbpress' )
    		) );
    
    		parent::__construct( false, __( '(rew) Login Widget', 'bbpress' ), $widget_ops );
    	}
    
    	/**
    	 * Register the widget
    	 *
    	 * @since bbPress (r3389)
    	 *
    	 * @uses register_widget()
    	 */
    	public static function register_widget() {
    		register_widget( 'Rew_Login_Widget' );
    	}
    
    	/**
    	 * Displays the output, the login form
    	 *
    	 * @since bbPress (r2827)
    	 *
    	 * @param mixed $args Arguments
    	 * @param array $instance Instance
    	 * @uses apply_filters() Calls 'bbp_login_widget_title' with the title
    	 * @uses get_template_part() To get the login/logged in form
    	 */
    	public function widget( $args = array(), $instance = array() ) {
    
    		// Get widget settings
    		$settings = $this->parse_settings( $instance );
    
    		// Typical WordPress filter
    		$settings['title'] = apply_filters( 'rew_widget_title', $settings['title'], $instance, $this->id_base );
    
    		// bbPress filters
    		$settings['title']    = apply_filters( 'rew_login_widget_title',    $settings['title'],    $instance, $this->id_base );
    		$settings['register'] = apply_filters( 'rew_login_widget_register', $settings['register'], $instance, $this->id_base );
    		$settings['lostpass'] = apply_filters( 'rew_login_widget_lostpass', $settings['lostpass'], $instance, $this->id_base );
    
    		echo $args['before_widget'];
    
    		if ( !empty( $settings['title'] ) ) {
    			echo $args['before_title'] . $settings['title'] . $args['after_title'];
    		}
    
    		if ( !is_user_logged_in() ) : ?>
    
    			<form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form">
    				<fieldset>
    					<legend><?php _e( 'Log In', 'bbpress' ); ?></legend>
    
    					<div class="bbp-username">
    						<input type="text" name="log" placeholder = "Username" value="<?php bbp_sanitize_val( 'user_login', 'text' ); ?>" size="20" id="user_login" tabindex="<?php bbp_tab_index(); ?>" />
    						
    					
    					</div>
    
    					<div class="bbp-password">
    						<input type="password" name="pwd" placeholder = "Password"  value="<?php bbp_sanitize_val( 'user_pass', 'password' ); ?>" size="20" id="user_pass" tabindex="<?php bbp_tab_index(); ?>" />
    					</div>
    
    					<div class="bbp-remember-me">
    						<input type="checkbox" name="rememberme" value="forever" <?php checked( bbp_get_sanitize_val( 'rememberme', 'checkbox' ), true, true ); ?> id="rememberme" tabindex="<?php bbp_tab_index(); ?>" />
    						<label for="rememberme"><?php _e( 'Remember Me', 'bbpress' ); ?></label>
    					</div>
    
    					<div class="bbp-submit-wrapper">
    
    						<?php do_action( 'login_form' ); ?>
    
    						<button type="submit" name="user-submit" id="user-submit" tabindex="<?php bbp_tab_index(); ?>" class="button submit user-submit"><?php _e( 'Log In', 'bbpress' ); ?></button>
    
    						<?php bbp_user_login_fields(); ?>
    
    					</div>
    
    					<?php if ( !empty( $settings['register'] ) || !empty( $settings['lostpass'] ) ) : ?>
    
    						<div class="bbp-login-links">
    
    							<?php if ( !empty( $settings['register'] ) ) : ?>
    
    								<a href="<?php echo esc_url( $settings['register'] ); ?>" title="<?php esc_attr_e( 'Register', 'bbpress' ); ?>" class="bbp-register-link"><?php _e( 'Register', 'bbpress' ); ?></a>
    
    							<?php endif; ?>
    
    							<?php if ( !empty( $settings['lostpass'] ) ) : ?>
    
    								<a href="<?php echo esc_url( $settings['lostpass'] ); ?>" title="<?php esc_attr_e( 'Forgot Your Password', 'bbpress' ); ?>" class="bbp-lostpass-link"><?php _e( 'Forgot Your Password', 'bbpress' ); ?></a>
    
    							<?php endif; ?>
    
    						</div>
    
    					<?php endif; ?>
    
    				</fieldset>
    			</form>
    
    		<?php else : ?>
    
    			<div class="bbp-logged-in">
    				<a href="<?php bbp_user_profile_url( bbp_get_current_user_id() ); ?>" class="submit user-submit"><?php echo get_avatar( bbp_get_current_user_id(), '40' ); ?></a>
    				<h4><?php bbp_user_profile_link( bbp_get_current_user_id() ); ?></h4>
    
    				<?php bbp_logout_link(); ?>
    			</div>
    
    		<?php endif;
    
    		echo $args['after_widget'];
    	}
    
    	/**
    	 * Update the login widget options
    	 *
    	 * @since bbPress (r2827)
    	 *
    	 * @param array $new_instance The new instance options
    	 * @param array $old_instance The old instance options
    	 */
    	public function update( $new_instance, $old_instance ) {
    		$instance             = $old_instance;
    		$instance['title']    = strip_tags( $new_instance['title'] );
    		$instance['register'] = esc_url_raw( $new_instance['register'] );
    		$instance['lostpass'] = esc_url_raw( $new_instance['lostpass'] );
    
    		return $instance;
    	}
    
    	/**
    	 * Output the login widget options form
    	 *
    	 * @since bbPress (r2827)
    	 *
    	 * @param $instance Instance
    	 * @uses BBP_Login_Widget::get_field_id() To output the field id
    	 * @uses BBP_Login_Widget::get_field_name() To output the field name
    	 */
    	public function form( $instance = array() ) {
    
    		// Get widget settings
    		$settings = $this->parse_settings( $instance ); ?>
    
    		<p>
    			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
    			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /></label>
    		</p>
    
    		<p>
    			<label for="<?php echo $this->get_field_id( 'register' ); ?>"><?php _e( 'Register URI:', 'bbpress' ); ?>
    			<input class="widefat" id="<?php echo $this->get_field_id( 'register' ); ?>" name="<?php echo $this->get_field_name( 'register' ); ?>" type="text" value="<?php echo esc_url( $settings['register'] ); ?>" /></label>
    		</p>
    
    		<p>
    			<label for="<?php echo $this->get_field_id( 'lostpass' ); ?>"><?php _e( 'Lost Password URI:', 'bbpress' ); ?>
    			<input class="widefat" id="<?php echo $this->get_field_id( 'lostpass' ); ?>" name="<?php echo $this->get_field_name( 'lostpass' ); ?>" type="text" value="<?php echo esc_url( $settings['lostpass'] ); ?>" /></label>
    		</p>
    
    		<?php
    	}
    
    	/**
    	 * Merge the widget settings into defaults array.
    	 *
    	 * @since bbPress (r4802)
    	 *
    	 * @param $instance Instance
    	 * @uses bbp_parse_args() To merge widget settings into defaults
    	 */
    	public function parse_settings( $instance = array() ) {
    		return bbp_parse_args( $instance, array(
    			'title'    => '',
    			'register' => '',
    			'lostpass' => ''
    		), 'login_widget_settings' );
    	}
    }
    
    add_action( 'widgets_init', function(){
         register_widget( 'Rew_Login_Widget' );
    });

    crystalleeanne
    Participant

    @crystalleeanne

    You are absolutely fantastic, thank you so much! 🙂

    I was prepared to beat my head against a wall for at least 4 hours trying to figure this out but now my noggin is safe hehehe. lol 😀

    Thanks again and cheers,
    C


    Robin W
    Moderator

    @robin-w

    no problem !


    ahd904
    Participant

    @ahd904

    Hi Robin @robin-w,

    I was hoping that i could pick up something from this thread.

    My friend is trying to build a forum with placeholder embedded in the textfield area but for just one specific forum.

    Would you be able to give us an idea how we can modify a specific php file which can allow us to achieve this.

    So, to make this one more clear.

    1) there is forum with ID= 1
    2) when writing new topics, wants users to see placeholder in the textfield area.
    ** just for this specific forum ** is quite important fact for us.

    Thank you for your help in advance.

    Thank you.


    Omar
    Participant

    @rashedfoundation

    Hi Robin W, thank you for providing the above code! It is just what I’ve been looking for!

    I have a question. When I was testing, I noticed if I entered invalid login info, there was no redirect or error message, but it did display that in my address bar. What accounts for what happens on login failure?

    Here is a sample that displayed in my browser after login failure:

    Upside

    The site I’m testing on is this one:

    http://www.rashedlightsways.com

    Also, small second question. It happens often that I’m on a site that I *think* I’ve registered on, but haven’t. If someone enters a login that is not correct AND that username doesn’t currently exist, is there a way to redirect to the registration page WITH that username?

    So, for example, I type in username: MyFaveUser pw: 1234, and it doesn’t exist in my user table, so the user is redirected to “Hey, MyFaveUser doesn’t exist, but you can register with it! It’s available!” and then autofill the username field with MyFaveUser and leave the pw field blank?

    I’ve been trying to bridge together new user registration and login in one field, and thought that might be a way to do it.

    Thank you so very much!

    – Omar
    “Let Your Light Shine”


    Robkk
    Moderator

    @robkk

    @rashedfoundation

    Also, small second question. It happens often that I’m on a site that I *think* I’ve registered on, but haven’t. If someone enters a login that is not correct AND that username doesn’t currently exist, is there a way to redirect to the registration page WITH that username?

    So, for example, I type in username: MyFaveUser pw: 1234, and it doesn’t exist in my user table, so the user is redirected to “Hey, MyFaveUser doesn’t exist, but you can register with it! It’s available!” and then autofill the username field with MyFaveUser and leave the pw field blank?

    This is some custom development , I suggest you hire a developer if you need help.

    As for the login shortcode issue , it might be best for you to link to the default WordPress login page if you are experiencing issue with it. Or just use a better front-end authentication plugin.


    PinkishHue
    Participant

    @pinkishhue

    Please can someone advise how the code above could be used only if using the reply form within a certain forum? e.g Forum ID 20

    I’ve tried the following at a guess but it’s not working…

    add_filter( 'bbp_get_the_content', 'amend_reply', 10, 3);
    
    Function amend_reply ($output, $args, $post_content) {
    if ( bbp_is_single_forum('20') ) {
    if ($args['context'] == 'reply' && $post_content == '') $output=str_replace('></textarea>', 'placeholder="Reply..." ></textarea>',$output) ;
    return $output ;
    }
    }
    

    or

    add_filter( 'bbp_get_the_content', 'amend_reply', 10, 3);
    
    Function amend_reply ($output, $args, $post_content) {
    if ($args['context'] == 'reply' && $post_content == '' && bbp_is_single_forum('20') ) $output=str_replace('></textarea>', 'placeholder="Reply..." ></textarea>',$output) ;
    return $output ;
    }
    

    or the same but using ‘bbp_is_forum_archive()’

    Many thanks for any help anyone can give me.

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