Skip to:
Content

BuddyPress.org

Changeset 3347 for trunk/bp-forums.php


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

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

File:
1 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' );
Note: See TracChangeset for help on using the changeset viewer.