Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/12/2017 02:41:37 PM (7 years ago)
Author:
hnla
Message:

Nouveau: re-factor bp_nouveau_signup_form error handling

Commit:

  1. Re-factors the signup template for new class token rendering & error checking & display of BP signup errors.
  2. Adds new function to provide html template markup for error string rendering.

Previously the signup form function rendered the BP global signup->errors via the BP action/do_action, proving hard to style messages in keeping with other site messages.

Commit builds a new function to pass the BP global buddypress()->signup->errors[ $name ] to, rendering the message string in suitable html. This function may be re-used for any additional in page error messages falling outside the Nouveau feedback message array.

Additionally no means of easily identifying the error fields existed, they would display as per browser 'required=required' styling. If BP global errors are set in each loop pass we generate a class 'invalid' to use to style the input on and that matches to the HTML5 pseudo class.

Props hnla, DJPaul, boonebgorges

Fixes #7642

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/template-tags.php

    r11707 r11770  
    740740
    741741    } elseif ( ! empty( $bp_nouveau->object_nav ) ) {
     742
    742743        $bp_nouveau->displayed_nav = $bp_nouveau->object_nav;
    743744
     
    752753         */
    753754        $nav = apply_filters( 'bp_nouveau_get_nav', $nav, $n );
     755
    754756    }
    755757
     
    20752077
    20762078    foreach ( $fields as $name => $attributes ) {
     2079        $classes = '';
     2080
    20772081        list( $label, $required, $value, $attribute_type, $type, $class ) = array_values( $attributes );
    20782082
     
    21332137        }
    21342138
    2135         if ( ! empty( $class ) ) {
    2136             // In case people are adding classes..
    2137             $classes = explode( ' ', $class );
    2138             $class = ' class="' . esc_attr( join( ' ', array_map( 'sanitize_html_class', $classes ) ) ) . '"';
    2139         }
    2140 
    2141         // Do not fire the do_action to display errors for the private radio.
     2139        // Do not run function to display errors for the private radio.
    21422140        if ( 'private' !== $value ) {
     2141
    21432142            /**
    2144              * Fires and displays any member registration field errors.
     2143             * Fetch & display any BP member registration field errors.
    21452144             *
    2146              * @since 1.1.0 (BuddyPress)
     2145             * Passes BP signup errors to Nouveau's template function to
     2146             * render suitable markup for error string.
    21472147             */
    2148             do_action( "bp_{$name}_errors" );
     2148            if( isset( buddypress()->signup->errors[ $name ] ) ) {
     2149                nouveau_error_template( buddypress()->signup->errors[ $name ] );
     2150                $invalid = 'invalid';
     2151            }
     2152        }
     2153
     2154        if ( isset( $invalid ) && isset( buddypress()->signup->errors[ $name ] ) ) {
     2155            if ( ! empty( $class ) ) {
     2156                $class = $class . ' ' . $invalid;
     2157            } else {
     2158                $class = $invalid;
     2159            }
     2160        }
     2161
     2162        if ( $class ) {
     2163            $class = sprintf(
     2164                ' class="%s"',
     2165                esc_attr( join( ' ', array_map( 'sanitize_html_class', explode( ' ', $class ) ) ) )
     2166            );
    21492167        }
    21502168
     
    22322250    }
    22332251}
     2252
     2253/**
     2254 * Display supplemental error or feedback messages.
     2255 *
     2256 * This template handles in page error or feedback messages e.g signup fields
     2257 * 'Username exists' type registration field error notices.
     2258 *
     2259 * @param string $message required: the message to display.
     2260 * @param string $type optional: the type of error message e.g 'error'.
     2261 *
     2262 * @since 1.0.0
     2263 */
     2264function nouveau_error_template( $message = '', $type = '' ) {
     2265    if ( ! $message ) {
     2266        return;
     2267    }
     2268
     2269    $type = ( $type ) ? $type : 'error';
     2270    ?>
     2271
     2272    <div class="<?php echo esc_attr( 'bp-messages bp-feedback ' . $type ); ?>">
     2273        <span class="bp-icon" aria-hidden="true"></span>
     2274        <p><?php echo esc_html( $message ); ?></p>
     2275    </div>
     2276
     2277    <?php
     2278}
Note: See TracChangeset for help on using the changeset viewer.