Skip to:
Content

BuddyPress.org

Changeset 3347


Ignore:
Timestamp:
11/03/2010 11:55:29 PM (16 years ago)
Author:
boonebgorges
Message:

Better handling of error messages during the creation of forum topics. Fixes #947

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums.php

    r3322 r3347  
    6767
    6868                                if ( $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) {
    69                                         if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
    70                                                 bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
    71                                         else
    72                                                 bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
    73 
    74                                         bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
     69                                        if ( empty( $_POST['topic_title'] ) )
     70                                                $error_message = __( 'Please provide a title for your forum topic.', 'buddypress' );
     71                                        else if ( empty( $_POST['topic_text'] ) )
     72                                                $error_message = __( 'Forum posts cannot be empty. Please enter some text.', 'buddypress' );
     73                                       
     74                                        if ( $error_message ) {
     75                                                bp_core_add_message( $error_message, 'error' );
     76                                                $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
     77                                        } else {
     78                                                if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) ) {
     79                                                        bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
     80                                                        $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
     81                                                } else {
     82                                                        bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
     83                                                        $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
     84                                                }
     85                                        }
     86                                       
     87                                        bp_core_redirect( $redirect );
     88                               
    7589                                } else {
    7690                                        bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
  • trunk/bp-groups.php

    r3331 r3347  
    477477                                        groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id );
    478478
    479                                 if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
    480                                         bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
    481                                 else
    482                                         bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
    483 
    484                                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' );
     479                                if ( empty( $_POST['topic_title'] ) )
     480                                        $error_message = __( 'Please provide a title for your forum topic.', 'buddypress' );
     481                                else if ( empty( $_POST['topic_text'] ) )
     482                                        $error_message = __( 'Forum posts cannot be empty. Please enter some text.', 'buddypress' );
     483                               
     484                                if ( $error_message ) {
     485                                        bp_core_add_message( $error_message, 'error' );
     486                                        $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
     487                                } else {
     488                                        if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) ) {
     489                                                bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
     490                                                $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
     491                                        } else {
     492                                                bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
     493                                                $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
     494                                        }
     495                                }
     496                               
     497                                bp_core_redirect( $redirect );
     498                               
    485499                        }
    486500
Note: See TracChangeset for help on using the changeset viewer.