944,161 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 15531
  • Perl RSS
You are currently viewing page 1 of this multi-page discussion thread
May 23rd, 2005
0

Guestbook help. Post in two different spots.

Expand Post »
Hi everyone, I have had great success with those who helped me get my guestbook working in being able to post large amounts of text. Now I have one other problem I'm trying to figure out.

I'm using the perl guestbook from Matt's Script Archive to allow users at my website to post stories to the site. It posts their name, email, the story name, and the entire story. Now the page is getting quite a few stories on it, but the problem is, they all just get posted on after another down the page, making for a lot of scrolling down the page to find a story. I did get my script to post a link with every story that takes you back to the top of the page, but now, it would be nice if the script could also take the name of the story, and in addition to posting the whole story on the page, create a link at the top of the page going to each story.

This is difficult, because the guestbook is basically just posting their stories on top of all the other stories, and pushing the old ones down. How do I get it to also post something in say a table or something at the top of the page? Ok, maybe not in a table, but in some organized manner at the top.
Thanks for you help,
Nate
Similar Threads
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
May 26th, 2005
0

Re: Guestbook help. Post in two different spots.

I've been Looking at your code, and what you are wanting to do is going to be a little bit of work. It's a pain, because, the guestbook is saved as an HTML document, and then parsed and displayed. The reason this is a problem is because we have to set our reference point in the HTML document. If you view the script, you'll see the line that looks for a begin point: if (/<!--begin-->/) {, the <!--begin--> is actually an HTML comment, that is in your HTML document. If you were to load your guestbook in a web browser, right click, and view page source, you would see that line at the top just before the guestbook entries are displayed. That's the key to tell the script, that now begins the entries. I am posting to let you know that I haven't forgotten about you, but that I'm looking at methods that will work effeciently for this script.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 26th, 2005
0

Re: Guestbook help. Post in two different spots.

Thanks for your reply. I was thinking the same thing. I noticed the reference point, as I had to make sure to put it in my web page to make sure the guestbook would work. I was thinking though, couldn't I just make another custom comment in my webpage, and then use the same code that looks for the other comment, only change the comment it looks for, and have it post after that? That way, the code would run, post the regular guestbook stuff after the first comment, then after that code runs, and would paste a copy of that code beneath it, change the comment to whatever else I specify, and it would go back to the HTML document, and post wherever it finds that code?

Even if it wouldn't work going in that order, I could switch it around, and have it post the link first, then post the guestbook stuff later down. Let me know what you think.
Thanks,
Nate
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
May 26th, 2005
0

Re: Guestbook help. Post in two different spots.

Well, I know that HTML allows you set labels.... such as:
Perl Syntax (Toggle Plain Text)
  1. <A name="section1">Introduction</A>

And Then You use the link such as:
Perl Syntax (Toggle Plain Text)
  1. <A href="#section1">Jump To Intro</A>

If they click on the link that says "Jump To Intro" it will jump (move the scroll bar and everything) down to the link with the name "section1". The problem I'm having, is that it looks to me like the cgi never accepts a story "name". For example:
Perl Syntax (Toggle Plain Text)
  1. $FORM{'realname'}
  2. $FORM{'username'}
  3. $FORM{'story'}

Ok, We have the persons real name, Their username, and their story (the content). I see no mention of a story "name" or "title" of the story. We can't do it by name or username, because then people can't post more than once, or it will throw things out of whack. Also, Keep in mind, that the CGI does NOT re-write the page. It only inserts itself into the top between <!--begin--> and the last posted entry. That means if you were to add a table or something in there, it would keep adding tables. You wouldn't be able to re-write the table, but you could probably add to it.

I personally don't care for matt's guestbook perl script. No offense, but I don't like his method. The problem with re-writing it to work differently, or to completly re-write one for your site specifically, would mean an awful lot of copy and pasting, and probably wouldn't be worth that much time. If we can find a way to get a story name or title, we could probably do it with what we are working with.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 26th, 2005
0

Re: Guestbook help. Post in two different spots.

I actually do have a label calling the story name, it's just called "storyname". Here, I'll post the code for the whole thing here (but I'll change a couple things just to keep it safe and private):
Perl Syntax (Toggle Plain Text)
  1. #!/usr/bin/perl
  2. # Set Variables
  3. $guestbookurl = "http://www.MYSITEURL.com/stories.htm";
  4. $guestbookreal = "/PATH/TO/MY/STORIES/PAGE/stories.htm";
  5. $guestlog = "/PATH/TO/MY/LOG/storyguestlog.html";
  6. $cgiurl = "http://www.royandstellawood.com/cgi-bin/storyguestbook.pl";
  7. $date_command = "/bin/date";
  8.  
  9. # Set Your Options:
  10. $mail = 1; # 1 = Yes; 0 = No
  11. $uselog = 0; # 1 = Yes; 0 = No
  12. $linkmail = 0; # 1 = Yes; 0 = No
  13. $separator = 1; # 1 = <hr>; 0 = <p>
  14. $redirection = 0; # 1 = Yes; 0 = No
  15. $entry_order = 1; # 1 = Newest entries added first;
  16. # 0 = Newest Entries added last.
  17. $remote_mail = 1; # 1 = Yes; 0 = No
  18. $allow_html = 0; # 1 = Yes; 0 = No
  19. $line_breaks = 0; # 1 = Yes; 0 = No
  20. $fromaddress = 'EMAILADDRESS@MYURL.com';
  21. # If you answered 1 to $mail or $remote_mail you will need to fill out
  22. # these variables below:
  23. $mailprog = '/usr/lib/sendmail';
  24. $recipient = 'EMAILADDRESS@MYURL.com';
  25.  
  26. # Done
  27. ##############################################################################
  28.  
  29. # Get the Date for Entry
  30. $date = `$date_command +"%A, %B %d, %Y"`; chop($date);
  31. $shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);
  32.  
  33. # Get the input
  34. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  35.  
  36. # Split the name-value pairs
  37. @pairs = split(/&/, $buffer);
  38.  
  39. foreach $pair (@pairs) {
  40. ($name, $value) = split(/=/, $pair);
  41.  
  42. # Un-Webify plus signs and %-encoding
  43. $value =~ tr/+/ /;
  44. $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  45. $value =~ s/<!--(.|\n)*-->//g;
  46.  
  47. if ($allow_html != 1) {
  48. $value =~ s/<([^>]|\n)*>//g;
  49. }
  50.  
  51. $FORM{$name} = $value;
  52. }
  53.  
  54. # Print the Blank Response Subroutines
  55. #&no_comments unless $FORM{'comments'};
  56. #&no_name unless $FORM{'realname'};
  57.  
  58. # Begin the Editing of the Guestbook File
  59. open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
  60. @LINES=<FILE>;
  61. close(FILE);
  62. $SIZE=@LINES;
  63.  
  64. # Open Link File to Output
  65. open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
  66.  
  67. for ($i=0;$i<=$SIZE;$i++) {
  68. $_=$LINES[$i];
  69. if (/<!--begin-->/) {
  70.  
  71. if ($entry_order eq '1') {
  72. print GUEST "<!--begin-->\n";
  73. }
  74.  
  75.  
  76. if ( $FORM{'storyname'} ){
  77. print GUEST "<h1><b><center>$FORM{'storyname'}</center></h1></b><br>\n";
  78. }
  79. print GUEST "<a href=\"#Top\"><u>(return to top)</u></a><br>\n";
  80.  
  81. if ($FORM{'url'}) {
  82. print GUEST "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
  83. }
  84. else {
  85. print GUEST "Submitted by: <b>$FORM{'realname'}</b><br>";
  86. }
  87.  
  88. if ( $FORM{'username'} ){
  89. if ($linkmail eq '1') {
  90. print GUEST " \<<a href=\"mailto:$FORM{'username'}\">";
  91. print GUEST "$FORM{'username'}</a>\>";
  92. }
  93. else {
  94. print GUEST "Email: <b>$FORM{'username'}</b>";
  95. }
  96. }
  97.  
  98. print GUEST "<br>\n";
  99. print GUEST "Date Submitted: $date<br>\n";
  100.  
  101.  
  102.  
  103.  
  104. if ( $FORM{'intro'} ){
  105. print GUEST "Story Introduction: $FORM{'intro'}<p>\n";
  106. }
  107.  
  108.  
  109.  
  110. print GUEST "<b>Story:</b><br>\n";
  111. $story=$FORM{'story'};
  112. $story =~s/\n/<br>/gi;
  113. print GUEST "$story\n";
  114.  
  115.  
  116. print GUEST "<hr>\n\n";
  117.  
  118. if ($entry_order eq '0') {
  119. print GUEST "<!--begin-->\n";
  120. }
  121.  
  122. }
  123. else {
  124. print GUEST $_;
  125. }
  126. }
  127.  
  128. close (GUEST);
  129.  
  130.  
  131. # Log The Entry
  132.  
  133. if ($uselog eq '1') {
  134. &log('entry');
  135. }
  136.  
  137.  
  138. #########
  139. # Options
  140.  
  141. # Mail Option
  142. if ($mail eq '1') {
  143. open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
  144.  
  145. print MAIL "Reply-to: $FORM{'username'}\n";
  146. print MAIL "From: $FORM{'username'}\n";
  147. print MAIL "Subject: New Story Submission\n\n";
  148. print MAIL "$FORM{'realname'} from email address $FORM{'username'} has posted a story to the web site.\n\n";
  149. print MAIL "Name: $FORM{'realname'}\n";
  150. print MAIL "Name of Story: $FORM{'storyname'}\n";
  151. print MAIL "Introduction to Story: $FORM{'intro'}\n";
  152. print MAIL "Story:\n";
  153. print MAIL "$FORM{'story'}\n\n";
  154. print MAIL "-$date\n";
  155. print MAIL "------------------------------------------------------\n";
  156.  
  157. close (MAIL);
  158. }
  159.  
  160. if ($remote_mail eq '1' && $FORM{'username'}) {
  161. open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
  162.  
  163. print MAIL "To: $FORM{'username'}\n";
  164. print MAIL "From: $fromaddress\n";
  165. print MAIL "Subject: New Story Submission\n\n";
  166. print MAIL "You are receiving this email because you submitted a story to the website.\n";
  167. print MAIL "Below is what you submitted.\n\n";
  168. print MAIL "Name: $FORM{'realname'}\n";
  169. print MAIL "Email Address: $FORM{'username'}\n";
  170. print MAIL "Name of Story: $FORM{'storyname'}\n";
  171. print MAIL "Story:\n";
  172. print MAIL "$FORM{'story'}\n\n";
  173. print MAIL "-$date\n";
  174. close (MAIL);
  175. }
  176.  
  177. # Print Out Initial Output Location Heading
  178. if ($redirection eq '1') {
  179. print "Location: $guestbookurl\n\n";
  180. }
  181. else {
  182. &no_redirection;
  183. }
  184.  
  185.  
  186.  
  187. # Log the Entry or Error
  188. sub log {
  189. $log_type = $_[0];
  190. open (LOG, ">>$guestlog");
  191. if ($log_type eq 'entry') {
  192. print LOG "$ENV{'REMOTE_HOST'} - [$shortdate]<br>\n";
  193. }
  194. elsif ($log_type eq 'no_name') {
  195. print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No Name<br>\n";
  196. }
  197. elsif ($log_type eq 'no_comments') {
  198. print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No ";
  199. print LOG "Comments<br>\n";
  200. }
  201. }
  202.  
  203. # Redirection Option
  204. sub no_redirection {
  205.  
  206. # Print Beginning of HTML
  207. print "Content-Type: text/html\n\n";
  208. print "<html><head><title><center>Thank you.</center></title></head>\n";
  209. print "<body bgcolor=\"ece4dd\">\n";
  210. print "<body><h1><center>Thank you for submitting your story.</h1></center>\n";
  211. print "<body><Center>A copy of your story has been sent to your email address.</center>\n";
  212. print "<body><Center>Click <a href=\"/stories.htm\">HERE</a> to return to the stories page.</center>\n";
  213. print "<body><center>You may have to refresh the page to see your story.\n";
  214.  
  215.  
  216.  
  217. # Print End of HTML
  218. print "<hr>\n";
  219.  
  220. print "</body></html>\n";
  221.  
  222. exit;
  223. }

I know it's long posting all that, but I thought it would be somewhat helpful. Anyway, I figure I can just use the same code for posting the story, but change the comment in the HTML it looks for.

Then once I get it posting there, then couldn't I just name a tag $storylink={'storyname'} or something, and then just have it post somthing like:

Perl Syntax (Toggle Plain Text)
  1. print GUEST "<a href=\"#storyname\"><u>$FORM{'storyname'}</u></a><br>\n";

I know the syntax might not be correct, but wouldn't that work?

Then I guess if I can get that one working, then I would have to figure out how to get it to start posting in columns or something, so it doesn't just post this huge list of story names that you have to scroll down to see anyway.

I know this may be too much to do just re-writting matt's Script. But I couldn't find any other scripts out there to do this story posting thing. I found plenty of scripts that would post like a never-ending story type thing, but not like what I'm doing.
Thanks for your help.
Nate
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
May 26th, 2005
0

Re: Guestbook help. Post in two different spots.

Actually, I think you have it down pat. All you need to do is use the link like you showed above, at each story name, but like:
Perl Syntax (Toggle Plain Text)
  1. print GUEST "<a href=\"$FORM{'storyname'}\"><u>$FORM{'storyname'}</u></a><br>\n";

or maybe even:
Perl Syntax (Toggle Plain Text)
  1. print GUEST "<a href=\"" . $FORM{'storyname'} . "\"><u>$FORM{'storyname'}</u></a><br>\n";

But you have the concept and idea. Then to make the table at the top with the list of story names will be the only trick. I was thinking you could add it just like the other one, but you would have to have a reference point at the bottom of the table....like, just before </TABLE>, or something like that at the top. Example:
Perl Syntax (Toggle Plain Text)
  1. <TABLE>
  2. <TR>
  3. <TD>Link to Story 1</TD>
  4. </TR>
  5. <TR>
  6. <TD>Link to Story 2</TD>
  7. </TR>
  8. <!--add story here-->
  9. </TABLE>

Then your perl code (near where <!--begin--> is):
Perl Syntax (Toggle Plain Text)
  1. if (/<!--add story here-->/) {
  2. print GUEST "<TR>\n";
  3. print GUEST "<TD><A HREF=\"#$FORM{'storyname'}\">$FORM{'storyname'}</A></TD>
  4. print GUEST "</TR>\n";
  5. }
  6.  

That should work out fairly well. You seem to grasp the idea. Don't forget to add the reference point for the table at the top or whatever you plan to do. Look to me like it should work a charm
Let me know how it turns out.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 26th, 2005
0

Re: Guestbook help. Post in two different spots.

Thanks, your table idea looks like it will work out swell! Now I just need to find the time to play with the code and test it out. I haven't even done anything to it yet. I actually know nothing about Perl, except for what I've learned playing around with Matt's guestbook. It's been fun though. I'm going to play with it for the next couple days, and I'll let you know what I come up with.
Thanks for all your help and ideas!
Nate
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
May 26th, 2005
0

Re: Guestbook help. Post in two different spots.

it's my pleasure. On Another Note, I have written 3 tutorials, on writing your own CGI's with Perl. Right now it only covers checking if data exists, reading data from the page, and writing data to a file, but I plan to make a few more, and ultimately have it cover a how to build your own guestbook, or something similar. Whenever you have time, it might be beneficial for you to read them.... I've gotten a few requests for more, and a couple of questions sent to me through PM's about them, but they are fairly straight forward and easy to understand. Let me know if I can help you with anything else, and let me know the guestbook turns out for you.

CGI Tutorials:
http://www.daniweb.com/tutorials/forum84.html
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 26th, 2005
0

Re: Guestbook help. Post in two different spots.

Thanks! I'll check into it sometime.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
May 27th, 2005
0

Re: Guestbook help. Post in two different spots.

I guess I should look into your tutorial to get the answer to this, but I've been playing around with it, and it's doing something really funny. After several attempts, I've got it working somewhat, right now, I'm just having it post some words up in the top portion, cause if I can get that working, then getting it to post the link is no problem.

However, it will post the first one just fine. Then when I try to do it again, it posts the words, and posts them again. It's like it's posting what it's supposed to, plus a few. I think it has to do with this code that starts it:

Perl Syntax (Toggle Plain Text)
  1. for ($i=0;$i<=$SIZE;$i++) {
  2. $_=$LINES[$i];

But I'm not really sure. Here, I'll post just the part that is posting the story to the page, and you can tell me what you think.

Perl Syntax (Toggle Plain Text)
  1. for ($i=0;$i<=$SIZE;$i++) {
  2. $_=$LINES[$i];
  3. ####THIS IS THE PART I ADDED#########################33
  4. if (/<!--links-->/) {
  5.  
  6. print GUEST "TEST LINK<br>\n";
  7. }
  8.  
  9. ##########I ADDED THE STUFF ABOVE THIS LINE################
  10.  
  11. if (/<!--begin-->/) {
  12.  
  13. if ($entry_order eq '1') {
  14. print GUEST "<!--begin-->\n";
  15. }
  16.  
  17.  
  18. if ( $FORM{'storyname'} ){
  19. print GUEST "<h1><b><center>$FORM{'storyname'}</center></h1></b><br>\n";
  20. }
  21. print GUEST "<a href=\"#Top\"><u>(return to top)</u></a><br>\n";
  22.  
  23. if ($FORM{'url'}) {
  24. print GUEST "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
  25. }
  26. else {
  27. print GUEST "Submitted by: <b>$FORM{'realname'}</b><br>";
  28. }
  29.  
  30. if ( $FORM{'username'} ){
  31. if ($linkmail eq '1') {
  32. print GUEST " \<<a href=\"mailto:$FORM{'username'}\">";
  33. print GUEST "$FORM{'username'}</a>\>";
  34. }
  35. else {
  36. print GUEST "Email: <b>$FORM{'username'}</b>";
  37. }
  38. }
  39.  
  40. print GUEST "<br>\n";
  41. print GUEST "Date Submitted: $date<br>\n";
  42.  
  43.  
  44.  
  45.  
  46. if ( $FORM{'intro'} ){
  47. print GUEST "Story Introduction: $FORM{'intro'}<p>\n";
  48. }
  49.  
  50.  
  51.  
  52. print GUEST "<b>Story:</b><br>\n";
  53. $story=$FORM{'story'};
  54. $story =~s/\n/<br>/gi;
  55. print GUEST "$story\n";
  56.  
  57.  
  58. print GUEST "<hr>\n\n";
  59.  
  60.  
  61. if ($entry_order eq '0') {
  62. print GUEST "<!--begin-->\n";
  63. }
  64.  
  65. }
  66. else {
  67. print GUEST $_;
  68. }
  69. }

So like I said, it posts the first one just fine, but it adds to many links after the first one.
Thanks,
nate
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Newbie Needs Help
Next Thread in Perl Forum Timeline: Win32 API Struct





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC