TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-23-2008, 06:08 PM   #1 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 87
Thanks: 49
StevenF is on a distinguished road
Default Creating a guest book

Hello there,

Some one mentioned that I created a guest book to improve my PHP skills, I thought this was a really good idea and took on the challenge! Unfortunately I don't think I have the skills right now to be able to create one, but here's what I've done so far:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Guest Book</title>
  <link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
  
  <script language="JavaScript" type="text/JavaScript">

		<!--This will hide our code from old browsers
		   
		  // JavaScript code goes here

      function validateForm()
      {
         with (document.guest_book) {
            
            errorfields=""
            
            //Check Name
            if (username.value == "") {
               errorfields=errorfields + "Name \n"
            }
            
            //Check email for @ and '.'
            if ((Email.value.length <6) || (Email.value.indexOf('@') <0) || (Email.value.indexOf('.') <0))  {
                errorfields=errorfields + "Please enter a valid Email address \n"
            }
            
            //Check comment
            if (comment.value == "") {
               errorfields=errorfields + "Please write your comment \n"
            }
            
            
            if (errorfields!="") {
               alert("The following fields much be entered: \n\n"  + errorfields)
               return false;
            }
        }
        return true;
      }

	// End hiding script from non-JavaScript browsers-->

	   </script>
	   
	   <noscript>Your browser has disabled Javascript</noscript>
	   
</head>
<body>

<!--Sign guest book form-->

<div align="center">
  <form name="guest_book" id="guestbooktable" method="post" action="results.php" onSubmit="return validateForm()">
    <table>
      <tr>
        <td>  *Name:   </td>
        <td>  <input type=text name=username size=30 /> </td>
      </tr>
      
      <tr>
        <td></td>
        <td></td>
      </tr>
      
      <tr>
        <td>  Email:   </td>
        <td>  <input type=text name=Email size=30 /> </td>
      </tr>
      
      <tr>
        <td></td>
        <td></td>
      </tr>
      
      <tr>
        <td>  Website:   </td>
        <td>  <input type=text name=website size=30 /> </td>
      </tr>
      
      <tr>
        <td></td>
        <td></td>
      </tr>
      
      <tr>
        <td>  Comment:   </td>
        <td>  <textarea name=comment rows=5 cols=40></textarea> </td>
      </tr>
      
       <tr>
        <td>  </td>
        <td>  <input type=submit name=submit value=Submit /> <input type=reset name=reset value=Reset /> </td>
      </tr>
    </table> 
  </form>
</div>
</body>
</html>
I've created a form and validated all the fields. I've then created a PHP page:

Code:
<?
$username=$_POST['username'];
$email=$_POST['Email'];
$websiteurl=$_POST['website'];
$comment=$_POST['comment'];
?>

<head>
	<title>Cookies</title>
		<script language="JavaScript" type="text/JavaScript">
			<!--This will hide our code from old browsers
		
		//Date
       now = new Date
       
	   dayNames = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
              
	   monthNames = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",              "December")

		dateNames = new Array ( "", "1st",  "2nd",  "3rd",  "4th",  "5th",  "6th",  "7th",  "8th", "9th", "10th", "11th", "12th", "13th", "14th",             "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st")
</script>
	   
	   <noscript>Your browser has disabled Javascript</noscript>
</head>
	
<div align="center">
	<table border="1">
	  <tr>
		<td width="74" rowspan="2">&nbsp;</td>
		<td width="435">
			<? echo $username; ?>  | <? echo $email; ?>  | 
			<script  language="javascript"  type="text/javascript">
              //Day
              document.writeln(dayNames[now.getDay()])
              //Date
              document.writeln(dateNames[now.getDate()])
              //Month
              document.writeln(monthNames[now.getMonth()])
              //Year
              document.write(now.getFullYear())

              </script>
		</td>
	  </tr>
	  <tr>
		<td><? echo $comment; ?></td>
	  </tr>
	</table>
</div>
What it does at the moment is shows all of the data entered in the form by using _POST. I'm not sure yet how I get that data to stay there so I can exit the page and leave another comment. Is this difficult?

Thanks,
Steven
StevenF is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:38 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design