pazza Posted July 17, 2007 Share Posted July 17, 2007 Ok, so I'm trying to set up a guestbook. I used one of these basic php scripts and customized it a little bit, but there are still a few changes i want to make. 1. Most importantly, I want new posts to appear at the top instead of the bottom. 2. Can I limit the text entered in the textboxes, to 100 characters. 3. Is there any way i can stop blank forms being submitted? 4. I can get the date shown, but i want it in '16.07.07' format, NOT 'Tuesday, July 16th 07' www.steparry.com/guestbook3.php Heres my script: <?PHP $nob = "<IMG SRC='speech1.jpg'>"; $nobs = "<HR width='100%' color='#00d214' size='1'>"; $filename = "guestbook3.txt"; #CHMOD to 666 $text = ""; if (isset($_POST["submit"])) { $name = htmlspecialchars($_POST["name"]); $message = htmlspecialchars($_POST["message"]); $date = date ("l, F jS, Y"); $time = date ("h:i A"); $value = $message."<br>\n<span style=\"font-family: verdana, arial, sans-serif; font-size: 70%; color: #505050;\">Posted by <B>$name</B>.\n</span>\n<break>\n$nobs\n$nob\n"; ##Write the file## $fp = fopen ($filename, "a"); if ($fp) { fwrite ($fp, $value); fclose ($fp); } else { echo ("Your entry could not be added."); } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Guestbook</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <BODY topmargin="0" leftmargin="0" rightmargin="0" link="black" alink="black" vlink="black"> <table border="0" cellpadding="0" cellspacing="0" height=100% width=100%> <tr> <td width="200" height="100%" bgcolor="#ffffff"> <form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="post"> <p><font size="2" face="arial"> Name: <br> <input type="text" name="name" size=18 style="border-color: black; border-width: 1px;"> <br> Message:<br> <textarea name="message" rows="3" cols="18" style="border-color: black; border-width: 1px;"></textarea><br> <input type="submit" name="submit" value="submit"></p> </form> <?PHP $contents = @file($filename) or die("No files in guestbook."); foreach ($contents as $line_num => $line) { $text .= $line; } $text = split("<break>", $text); for ($i=0; $i<count($text)-1; $i++) { echo "<div style=\"border: gray 0px solid; padding: 3px; font-family: arial, sans-serifs;\">"; echo $text[$i]; echo "</div>"; } ?> </td> <td width="200" height="100%"> </td> </tr> </table> </BODY> </HTML> Any help will be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
lur Posted July 17, 2007 Share Posted July 17, 2007 1. Most importantly, I want new posts to appear at the top instead of the bottom. //change $text = split("<break>", $text); //to $text = array_reverse(split("<break>", $text)); 2. Can I limit the text entered in the textboxes, to 100 characters. 3. Is there any way i can stop blank forms being submitted? //after $message = htmlspecialchars($_POST["message"]); //add if (empty($message)) { exit('You cannot post an empty message.'); } if (strlen($message) > 100) { exit('Your message is too long.'); } 4. I can get the date shown, but i want it in '16.07.07' format, NOT 'Tuesday, July 16th 07' Change the format string ("l, F jS, Y"), read the manual on date(). Quote Link to comment Share on other sites More sharing options...
pazza Posted July 17, 2007 Author Share Posted July 17, 2007 Thank you so much for that, it would have taken me a lifetime. A couple more questions 1. Theres a blank entry that stay at the top. Tried deleting it from the .txt file but didnt work. 2. If someone enters a long piece of text, it stretches my table size. How do i prevent this? 3. Can i use an image file instead of the 'Message Too Long' and can it also be a Back button. Thanks again Oh and, 4. If i put this in a frame or a DIV box on my index page, will it work, or mess everything up. Quote Link to comment Share on other sites More sharing options...
pazza Posted July 17, 2007 Author Share Posted July 17, 2007 Another one, sorry 5. When I change my button code to TYPE="submit" to TYPE="image", it shows the .gif image, but the button stops working. cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.