Difference between revisions of "Pages Templates:Forum"

From Whirlwind eCommerce Wiki
Jump to: navigation, search
(New page: Forum pages can contain forum post listings and / or a post form. The listing and the form can be separate templates or combined into the same template. The post form can vary in many ways...)
 
Line 3: Line 3:
 
Below are examples of various implementations
 
Below are examples of various implementations
  
=Basic forums listing and form page=
+
=Example: Basic post listing and submission form=
 
Display's all posts and includes a submission form at the bottom. Submissions will be redirected back to the page containing this form, with a message as to the success / failure of the post.
 
Display's all posts and includes a submission form at the bottom. Submissions will be redirected back to the page containing this form, with a message as to the success / failure of the post.
  

Revision as of 22:51, 12 March 2009

Forum pages can contain forum post listings and / or a post form. The listing and the form can be separate templates or combined into the same template. The post form can vary in many ways depending on the data you want to collect, security controls and restrictions set up in settings for forums.

Below are examples of various implementations

Example: Basic post listing and submission form

Display's all posts and includes a submission form at the bottom. Submissions will be redirected back to the page containing this form, with a message as to the success / failure of the post.

// only process forum requests and output if forums is available and selected for this page
// accessing global settings variable forums_available (sets forum availability for entire site)
// and page core variable $isForum (sets forum availability for specific page)
 
if($GLOBALS['iProducts']['forums_available'] AND $isForum){
   // get postings for current page
   // using core variable $page to get forum data for the current page we are in
   $forumArray = eV::pageForumPostsGet(NULL,$pageId,NULL,"post_createDate,post_handle,post_copy,post_title");
 
   // shortcut to the post array
   $postsArr = $forumArray['posts'];
 
   if(count($postsArr) > 0){
      // loop thru posts
      foreach($postsArr as $post){
         echo "<hr>" . $post['post_title'] . " by " . $post['post_handle'] . " on " . $post['post_createDate'];
         echo "<br>" . $post['post_copy'];
      };
   } else {
      // no posts to this forum, lets output this to visitors
      echo "no posts to this forum";
   };
 
 
	//////// post submission form ////////////////
	// anchor forumPostForm to so that kickbacks from submission function jump to the form
	echo "<a name=\"forumPostForm\"></a><form action=\"index.php\" method=\"post\" name=\"forumPostForm\">";
	// field for visitors to enter handle: must be 50 or less chars
	// only show this field if user NOT logged in (if logged in, handle will be pulled from user account)
	if(eV::authorizeIsLoggedIn()){
		echo "<br>Your entry will be posted under <i>" . $_SESSION['user']['handle'] . "</i>. This not you? <a href=\"index.php?fa=USER.logout\">Click here to log out</a>";
	} else {
		echo "<br>Enter a Handle: <input type=\"text\" name=\"handle\" size=25 maxlength=50>
		<br>Enter your Email Address: <input type=\"text\" name=\"emailAddress\" size=25 maxlength=50>";
	};
	// max length for post title is 100 chars
	echo "<br>Enter a Title for you post: <input type=\"text\" name=\"title\" size=50 maxlength=100>";
	// post has not size limit
	echo "<br>Enter you post: <textarea name=\"copy\" cols=50 rows=5></textarea>";
	// pass the current pageId - required
	echo "<input type=\"hidden\" name=\"pageId\" value=\"$pageId\">
	<input type=\"hidden\" name=\"fa\" value=\"FORUM.post\">";
	echo "<br><input type=\"submit\" value=\"Post!\">";
	// validate - this tells the system what fields must have value
	echo "<input type=\"hidden\" name=\"validate\" value=\"title,copy,handle\">";
 
	// redirect - this is where to send the visitor after the post has been accepted
	echo "<input type=\"hidden\" name=\"redirect\" value=\"index.php?pageId=$pageId&message=You post has been received. Once it is approved you will see it live on our site.\">";
	echo "</form>";
 
// end if foroums available and this is a forum
};