R
E
S
O
U
R
C
E
S
       Home      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: menus, buttons, etc.
_______________________

Send us your questions.
_______________________

site search by freefind
_______________________

HOME
SEO, Google, Privacy
   and Anonymity
Browser Insanity
JavaScript
Popups and Tooltips
Free Website Search
HTML Form Creator
Animation
Buttons and Menus
Counters
Captchas
Image Uploading
CSS and HTML
PHP
AJAX
XPATH
Website Poll
IM and Texting
Databases—MySQL
   or Not MySQL
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs




Free Personal Status Boards (PSB™)

Free Standard Free PSB

Free PSB Pro Version

Free Social PSB

Free Social PSB Plus (with Email)

Free Business PSB

Free Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

Form to Send Private Message on Your Website

private messaging

This page is a tutorial on putting a private message (PM) sending form on your website. It uses sessions, input length control on a textarea tag's input box, PHP, JavaScript, HTML, and a menu system. The menu on the side bar lets you send a message or check out your inbox or outbox, or delete messages from your inbox or outbox or logout. The screenshot above is the private message inbox.

Let's check out the code. It starts with a PHP include that insists on adding the php file checkid.php to this page's content. All that's in this file is:

session_start();

if(!isset($_SESSION['sessionid'])){

session_unset();
session_destroy();

header('location: message-login.php');

}else{
// session logged
}

This just does what it ought to: start a session (it started in the login page, actually, but we can say we restarted it even though we merely continued it and restarted the session timeout clock which is set for 24 to 48 minutes, depending on the PHP installation directives). We then check the session variable "sessionid" which was saved at login. If it's not set, the user is sent to the login page after unsetting and destroying the session. If it is set, the user gets to continue the script since the else conditional leads only to a comment that does nothing, but says it all: "session logged." So the user is okay and good to go.

Then we get the session variable "username" into the PHP variable $U. We'll need this. Then we do a few cosmetic adjustments to the page with the CSS style properties in the fixwidth() function in JavaScript. Then there is the textCounter() function which does input length control on a textarea tag's input box. There is no maxlength attribute for textarea tags, but this does the same job—only better, since it has a counter associated with it that shows the user how many characters s/he can still type before the 700-character allotment is used up. At that point, it stops any more entering into the textarea box. It does this by use of the
substring() function which trims off the just added character from the string once the maximum has beed reached. The OnKeyDown and OnKeyUp events in the textarea box run the textCounter() function, using as parameters this.form.message as the field whose value's length is continuously compared to maxlength, this.form.remLen as the countfield value that keeps getting reduced as long as the maxlength has not been reached, and 700 as the maxlimit number. More info on this.form.

The HTML page title gets a bit of PHP thrown into it as it needs to include the user's username. HTML does not mind this at all. The menu—just a series of links to the other pages of the private messaging app—comes next. Next comes the form. Its action is the PHP page send-message.php. The textarea box has 2 events that run the function already discussed. The input after the textarea box is a read only input box with 700 as its initial value, but all input decreases this number. And that's about it. Forms are pretty simple.

Name the file send-message-form.php

<?php
include_once"checkid.php";

$U=$_SESSION['username'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Form for Sending a Private Message</TITLE>
<meta name="description" content="Form for Sending a Private Message">
<meta name="keywords" content="Form for Sending a Private Message,Form for Submitting a Private Message,Send Message Form,Submit Message Form,Private Messaging,Private Message,php,javascript, dhtml, DHTML">
<script language="javascript">
mactest=(navigator.userAgent.indexOf("Mac")!=-1) //My browser sniffers
Netscape=(navigator.appName.indexOf("Netscape") != -1)
msafari=(navigator.userAgent.indexOf("Safari")!= -1)
wsafari=0; if(!mactest&&msafari){wsafari=1;msafari=0}
is_opera = 0; if(window.opera){is_opera=1}
is_ie_mac = 0; is_ie=0;if(document.all){is_ie=1}

function fixwidth(){if(Netscape||is_opera){e=document.getElementById('box');e.style.width='476px';e=document.getElementById('menu');e.style.width='116px';}}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit){field.value = field.value.substring(0, maxlimit);}
else{countfield.value = maxlimit - field.value.length;}}
</script>
<STYLE TYPE="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#ccc}
p, li {font:13px Verdana; color:black;text-align:left}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
h3 {font:bold 15px Verdana;}
#box {background-color:#eee;position:absolute;top:50px;left:250px;
width:500px;padding:10px;border:2px solid blue}
#menu {background-color:#eee;position:absolute;top:50px;left:0px;
width:130px;padding:5px;border:2px solid blue}
</STYLE>
</head>
<body onload="fixwidth()">
<h1>Form for Sending a Private Message (from <?php echo $U; ?>)</h1>
<div id='menu'>
<a HREF="send-message-form.php">Send Message</a><BR><BR>
<a HREF="message-inbox.php">Message Inbox</a><BR><BR>
<a HREF="message-outbox.php">Message Outbox</a><BR><BR>
<a HREF="message-delete-received.php">Delete Inbox<BR>Message</a><BR><BR>
<a HREF="message-delete-sent.php">Delete Outbox<BR>Message</a><BR><BR>
<a HREF="message-login.php">Login</a><BR><BR>
<a HREF="message-logout.php">Logout</a>
</div>
<div id='box'>
<form action="send-message.php" method="post" name="sendpm">
<table width='476'>
<tr>
<td width='120' align='right'>To Username</td>
<td width='356' align='left'>
<input type="text" name="touser" id="touser" size="35" maxlength="40">
</td>
</tr>
<tr>
<td width='120' align='right'>Subject</td>
<td width='356' align='left'>
<input type="text" name="subject" id="subject" size="35" maxlength="150">
</td>
</tr>
<tr>
<td width='120' align='right'>Message</td>
<td width='356' align='left'>
<textarea name="message" cols="35" rows="20" id="message" onKeyDown="textCounter(this.form.message,this.form.remLen,700)" onKeyUp="textCounter(this.form.message,this.form.remLen,700)"></textarea>
<input readonly type='text' name='remLen' size='3' maxlength='3' value="700"><br></td>
</tr>
<tr>
<td colspan="2">
<center><input type="submit" value="Send PM"></center>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>