Skip to:
Content
Pages
Categories
Search
Top
Bottom

Error messages are out of sight

  • @wpturk

    Participant

    When a user forgets to fill a field or makes a mistake on the topic form, the page reloads and error messages are at the bottom of the page. One has to scroll down to see them. Any workaround for this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @robin-w

    Moderator

    I’ve found that annoying in the past, and not bothered to think about correcting.

    This basic code will display the errors at the top, but I might look to improve on that in style pack

    add_action ('bbp_template_before_single_forum' , 'bbp_template_notices') ;
    
    add_action ('bbp_template_before_single_topic' , 'bbp_template_notices') ;

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    @robin-w

    Moderator

    this is what I might out in style pack

    add_action ('bbp_template_before_single_forum' , 'bsp_template_notices') ;
    
    add_action ('bbp_template_before_single_topic' , 'bsp_template_notices') ;
    
    function bsp_template_notices() {
    
    	// Bail if no notices or errors
    	if ( ! bbp_has_errors() ) {
    		return;
    	}
    
    	// Define local variable(s)
    	$errors = $messages = array();
    
    	// Get bbPress
    	$bbp = bbpress();
    
    	// Loop through notices
    	foreach ( $bbp->errors->get_error_codes() as $code ) {
    
    		// Get notice severity
    		$severity = $bbp->errors->get_error_data( $code );
    
    		// Loop through notices and separate errors from messages
    		foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
    			if ( 'message' === $severity ) {
    				$messages[] = $error;
    			} else {
    				$errors[]   = $error;
    			}
    		}
    	}
    
    	// Display errors first...
    	if ( ! empty( $errors ) ) : ?>
    
    		<div class="bbp-template-notice error" role="alert" tabindex="-1">
    			<ul>
    				<li>
    					<?php echo implode( "</li>\n<li>", $errors ); ?>
    					<a href="#new-post">
    					<?php _e('Click here to correct', 'bbp-style-pack') ; ?>
    					</a>
    				</li>
    			</ul>
    		</div>
    
    	<?php endif;
    
    }

    @wpturk

    Participant

    works like a charm, thanks Robin.

    @robin-w

    Moderator

    now in style pack

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