Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Support: Creating & Extending

Existing and new plugins/components and themes.

Adding ”Post To Forum Page” (11 posts)

Started 1 year ago by: LPH2005

  • Profile picture of LPH2005 LPH2005 said 1 year ago:

    [[Removed original text to help with the flow of the thread]]

    Objective: To create a page with a form that posts to forums.

    Update:: I have a WP page working though a template except the bb-attachments plugin does not show. See latest posts for code in template.

  • Profile picture of LPH2005 LPH2005 said 1 year ago:

    Ugh. I feel like I’m so close to getting this to work.

    Rather than try to create a BP page, a WP page was created with a template. The template contains the following code:

    <?php
    /*
    Template Name: Question
    */
    ?>
    
    <?php get_header() ?>
    
    	<div id="bp-container">
    
    		<div class="padder">
    
    			<div id="new-topic-post">
    
    			<br><br>
    
    			<h5>How To Ask A Great Question And Get It Answered</h5>
    			Maybe you are stuck on a homework problem or do not understand a particular concept. Don't panic. TheChemBook.com is a great place to ask your questions.
    			First search to see if someone else has asked about the problem. Next, search <a href="/wiki/index.php/TCB:_Chemistry_Online_Textbook">The Chemistry Text</a> by reading the section on the topic.
    			If none of this helps, start a new topic by completing the form below.
    			Start with a great headline. Avoid saying, "I'm lost" or "how do I do problem 12?"
    			A great headline might be "Determining Significant Figures - Captured Zeros"
    			Next, type as much detail as possible, for example, add the exact wording of the problem you are trying to answer.
    			Finally, explain the problem <strong>and what you have tried</strong>.
    			The more details you add then the faster someone can help you.
    			Teachers are available at irregular intervals, therefore, make sure that you help others with their questions, too.
    
    			<br><br>
    
    			<?php if ( is_user_logged_in() ) : ?>
    
    				<?php if ( bp_has_groups( 'user_id=' . bp_loggedin_user_id() . '&type=alphabetical&max=100&per_page=100' ) ) : ?>
    
    					<form action="" method="post" id="forum-topic-form" class="standard-form">
    
    						<?php do_action( 'groups_forum_new_topic_before' ) ?>
    
    						<a name="post-new"></a>
    						<h5><?php _e( 'Post a New Topic:', 'buddypress' ) ?></h5>
    
    						<label><?php _e( 'Title:', 'buddypress' ) ?></label>
    						<input type="text" name="topic_title" id="topic_title" value="" />
    
    						<label><?php _e( 'Content:', 'buddypress' ) ?></label>
    						<textarea name="topic_text" id="topic_text"></textarea>
    
    						<label><?php _e( 'Tags (comma separated):', 'buddypress' ) ?></label>
    						<input type="text" name="topic_tags" id="topic_tags" value="" />
    
    						<label><?php _e( 'Post In Group Forum:', 'buddypress' ) ?></label>
    						<select id="topic_group_id" name="topic_group_id">
    
    							<option value="">----</option>
    
    							<?php while ( bp_groups() ) : bp_the_group(); ?>
    
    								<?php if ( bp_group_is_forum_enabled() && 'public' == bp_get_group_status() ) : ?>
    
    									<option value="<?php bp_group_id() ?>"><?php bp_group_name() ?></option>
    
    								<?php endif; ?>
    
    							<?php endwhile; ?>
    
    						</select><!-- #topic_group_id -->
    
    						<?php do_action( 'groups_forum_new_topic_after' ) ?>
    
    						<div class="bp-submit">
    							<input type="submit" name="submit_topic" id="submit" value="<?php _e( 'Post Topic', 'buddypress' ) ?>" />
    							<input type="button" name="submit_topic_cancel" id="submit_topic_cancel" value="<?php _e( 'Cancel', 'buddypress' ) ?>" />
    						</div>
    
    						<?php wp_nonce_field( 'bp_forums_new_topic' ) ?>
    
    					</form><!-- #forum-topic-form -->
    
    				<?php else : ?>
    
    					<div id="message" class="info">
    						<p><?php printf( __( "You are not a member of any groups so you don't have any group forums you can post in. To start posting, first find a group that matches the topic subject you'd like to start. If this group does not exist, why not <a href='%s'>create a new group</a>? Once you have joined or created the group you can post your topic in that group's forum.", 'buddypress' ), site_url( BP_GROUPS_SLUG . '/create/' ) ) ?></p>
    					</div>
    
    				<?php endif; ?>
    
    			<?php endif; ?>
    
    			</div>
    
    		</div>
    
    	</div>
    
    <?php get_footer() ?>

    Now – the header has gone wild on the whole site, the buttons at the top right disappear on the WP page for ask-a-question, and NO submit button is showing when logged into the site.

    Link: http://www.thechembook.com/ask-a-question/

    Any thoughts on what is wrong with the code?

    Update: Looking at the source after the page loads – the form is not completing; that is, no </form> is being served.

  • Profile picture of LPH2005 LPH2005 said 1 year ago:

    Update:

    If I remove, <?php do_action( 'groups_forum_new_topic_before' ) ?> and <?php do_action( 'groups_forum_new_topic_after' ); ?> then the header loads properly, the submit buttons show

    BUT nothing posts to the forums. This is due to form action being incorrect. What should it be?

    Oh so close!

    Update to the update:

    It turns out that the file attachments portion of buddypress plugin aren’t present either. :(

  • Profile picture of LPH2005 LPH2005 said 1 year ago:

    OK ! It’s working with the exception of the file attachments (because I removed the do_action lines) but the page now posts to the proper forum. :)

    Here is the code:

    <?php
    /*
    Template Name: Question
    */
    ?>
    
    <?php get_header(); ?>
    
    	<div id="bp-container">
    
    		<div class="padder">
    
    			<div id="new-topic-post">
    
    			<?php if ( is_user_logged_in() ) : ?>
    
    			<div id="message" class="info">
    				<h1>IMPORTANT: This form does not work yet.</h1> <p style="font-color: red; font-weight: bold;">Please do not use this form.</p>
    			</div>
    
    			<br><br>
    
    			<h5>How To Ask A Great Question And Get It Answered</h5>
    			Maybe you are stuck on a homework problem or do not understand a particular concept. Don't panic. TheChemBook.com is a great place to ask your questions.
    			First search to see if someone else has asked about the problem. Next, search <a href="/wiki/index.php/TCB:_Chemistry_Online_Textbook">The Chemistry Text</a> by reading the section on the topic.
    			If none of this helps, start a new topic by completing the form below.
    			Start with a great headline. Avoid saying, "I'm lost" or "how do I do problem 12?"
    			A great headline might be "Determining Significant Figures - Captured Zeros"
    			Next, type as much detail as possible, for example, add the exact wording of the problem you are trying to answer.
    			Finally, explain the problem <strong>and what you have tried</strong>.
    			The more details you add then the faster someone can help you.
    			Teachers are available at irregular intervals, therefore, make sure that you help others with their questions, too.
    
    			<br><br>
    
    				<?php if ( bp_has_groups( 'user_id=' . bp_loggedin_user_id() . '&type=alphabetical&max=100&per_page=100' ) ) : ?>
    
    					<form action="/tutoring" method="post" id="forum-topic-form" class="standard-form" enctype="multipart/form-data">
    
    						<a name="post-new"></a>
    						<h5><?php _e( 'Post a New Topic:', 'buddypress' ) ?></h5>
    
    						<label><?php _e( 'Title:', 'buddypress' ) ?></label>
    						<input type="text" name="topic_title" id="topic_title" value="" />
    
    						<label><?php _e( 'Content:', 'buddypress' ) ?></label>
    						<textarea name="topic_text" id="topic_text"></textarea>
    
    						<label><?php _e( 'Tags (comma separated):', 'buddypress' ) ?></label>
    						<input type="text" name="topic_tags" id="topic_tags" value="" />
    
    						<label><?php _e( 'Post In Group Forum:', 'buddypress' ) ?></label>
    						<select id="topic_group_id" name="topic_group_id">
    
    							<option value="">----</option>
    
    							<?php while ( bp_groups() ) : bp_the_group(); ?>
    
    								<?php if ( bp_group_is_forum_enabled() && 'public' == bp_get_group_status() ) : ?>
    
    									<option value="<?php bp_group_id() ?>"><?php bp_group_name() ?></option>
    
    								<?php endif; ?>
    
    							<?php endwhile; ?>
    
    						</select><!-- #topic_group_id -->
    						<br /><br />
    						<div class="bp-submit">
    							<input type="submit" name="submit_topic" id="submit" value="<?php _e( 'Post Topic', 'buddypress' ); ?>" />
    							<input type="button" name="submit_topic_cancel" id="submit_topic_cancel" value="<?php _e( 'Cancel', 'buddypress' ); ?>" />
    						</div>
    
    						<?php wp_nonce_field( 'bp_forums_new_topic' ) ?>
    
    					</form><!-- #forum-topic-form -->
    
    				<?php else : ?>
    
    					<div id="message" class="info">
    						<p><?php printf( __( "You are not a member of any groups so you don't have any group forums you can post in. To start posting, first find a group that matches the topic subject you'd like to start. If this group does not exist, why not <a href='%s'>create a new group</a>? Once you have joined or created the group you can post your topic in that group's forum.", 'buddypress' ), site_url( BP_GROUPS_SLUG . '/create/' ) ) ?></p>
    					</div>
    
    				<?php endif; ?>
    
    			<?php else : ?>
    
    				<div id="message" class="info">
    					<p>You need to <a href="<?php echo site_url( 'wp-login.php' ) ?>">log in</a> <?php if ( bp_get_signup_allowed() ) : ?> or <?php printf( __( ' <a class="create-account" href="%s" title="Create an account">create an account</a>', 'buddypress' ), site_url( BP_REGISTER_SLUG . '/' ) ) ?><?php endif; ?> to participate in the tutoring area.</p>
    				</div>
    
    			<?php endif; ?>
    
    			</div>
    
    		</div>
    
    	</div>
    
    <?php get_footer(); ?>

    If you see a way to enhance this template then please let me know. The file attachment plugin isn’t working with this page (nor edit a topic) so something obvious is probably missing.

    Hope this helps someone else trying to get a page with a form to post to the forums ….

  • Profile picture of LPH2005 LPH2005 said 1 year ago:

    OK. I found duplicate lines of add_action in the forum-attachments-for-buddypress-bp-functions.php.

    I kept these lines (starting around 183) and removed the ones that I apparently added at the top of the php file.

    add_action('groups_forum_new_topic_after','bb_attachments_upload_form');
    add_action('groups_forum_new_reply_after', 'bb_attachments_upload_form');
    add_action('groups_forum_edit_post_after', 'bb_attachments_upload_form');
    add_action('bp_after_group_forum_post_new', 'bb_attachments_upload_form');
    add_action('bp_group_after_edit_forum_post', 'bb_attachments_upload_form');
    add_action('bp_group_after_edit_forum_topic', 'bb_attachments_upload_form');

    Now the hooks (do_action) are added to the template file question.php and the page loads properly. Unfortunately – the hook isn’t working – and the file upload function is not being presented.

    Oh – even closer :)

  • Profile picture of LPH2005 LPH2005 said 1 year ago:

    @boonebgorges

    This problem is narrowed to the firing of the add_action within forum-attachments-for-buddypress-bp-functions.php.

    A simple function / add_action is loaded in the theme functions.php then it fires on that question.php template. If that sample function/add_action is placed in the forum-attachments-for-buddypress-bp-functions.php file then it does not fire.

    This is the test function placed in the themes functions.php that works. Also added to plugin functions file and it fails.

    // Test question.php form hook
    function question_fire() {
    	echo "Testing the hook";
    }
    add_action('question_after', 'question_fire');

    I’m about ready to give up. Google searches are not leading me to an answer. And my knowledge is limited.

    Update I hope that didn’t seem negative. I’m at my limit and stretching :)

    OK. So, I know the forum attachment plugin is Boone’s bane … and I love that plugin .. so … press forward.

    I tried my test function in another active plugin (akismet) and it worked AND interestingly the test function works in forum-attachments-for-buddypress.php.

  • Profile picture of LPH2005 LPH2005 said 1 year ago:

    Wow. It turns out that the plugin is initialized using bp_init
    add_action( 'bp_init', 'bp_forum_attachments_init' );

    If this is changed to:
    add_action( 'init', 'bp_forum_attachments_init' );

    Then the test function fires.

    But, the add_action for the bb_attachment form does not fire.

    add_action( 'question_after', 'bb_attachments_upload_form' );

  • Profile picture of ewebber ewebber said 1 year ago:

    I’d be pretty interested in seeing how you get on with this

  • Profile picture of LPH2005 LPH2005 said 1 year ago:

    Everything works except the attachment plugin not working.

  • Profile picture of 4ella 4ella said 1 year ago:

    Very interesting question page and very useful ! I will try that out on my website too , thanks for this !! I am sure that I will come back for some advices , because if your knowledge is limited , mine is far mooooore limited -:)

  • Profile picture of ewebber ewebber said 1 year ago:

    @LPH2005 cool thanks, I will give it a go – although for the moment I have moved my form to the bottom of the discussions page and added an anchor tag http://www.yeahhackney.com/forums/#newform