HTML Goodies: PERL Primer, Part 7
WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
[What It All Means]
[The Postings Page]
OK, first we got the script to send email, then we got the script to post a thank you page, then we got the script to recognize branching. The next logical step is to have the script post whatever the users write so any and everybody can read what the users wrote.
I know it sounds like a daunting task, but it isn't. You'll actually be surprised at how easily I got the text to post. You just have to make a place for the text to post and the script will do the rest.
Take a look at it in action. You'll get a link to the postings page on the thank-you page after you submit your form.
New Posting Code
We'll start with the full script code. The new posting code is in blue. Notice there's a line right up top and then a block of code further down. look for them both.
The HTML code stays the same. Just like last time, if you're simply going to re-FTP these two files and replace what you had before, then there's no need to reset the modifications. If you do upload these as new files, then yes, you need to set modifications, 775 for the CGI and 644 for the HTML page.
What It All Means
Let's take it from the top, as they say. Here's the first new line of code. Notice I have it first in the script, just under the path to PERL. Keep it there. It helps you to keep the lines that denote variables away from the rest of the code. It looks like this:
The entire purpose of this line is to assign the absolute path to the page containing all of the posts to a scalar variable, "$guestbook".
Please understand this is the absolute path, not the path you see in the location bar. You can find your absolute path by telnetting into the directory where your posting page will sit and putting the command "pdw" (without the quotes).
Don't guess at this. Get the absolute path for darn sure.
Got it? Super. Moving along. The code that posts to a new page is next. It's a little wide, so look at it here.
We start by opening a file we give the handle "GUESTBOOK". Remember - capitalization counts in PERL.
That file can be found (<<) in the path represented by the variable $guestbook that we set up earlier. See how that works?
Next we grab and print to GUESTBOOK (the file we denoted earlier) the time the user posted the message from the information sent by the form. Everything that is sent by the user is within the variable, "ENV". We're just grabbing one section of it, the time. We use $currenttime to do that.
Next we print the user's name and then using the user's email address, build an email link. Notice we use double quotes in building the email address. If we didn't put the backslash in front of the quotes, the script would think the line was over and quit...error! But, by putting a backslash in front of the quote, the script sees it as something to be printed, rather than the end of the line. That's pretty cool, huh?
The next little blurb should look somewhat familiar to you. It's a branching method from Primer Six that will print a line depending on if the user signed up for the newsletter or not. Of course it has a line in case the user simply didn't answer.
Lastly we write a line denoting that the following is the feedback, and then finally print the feedback.
To end it, we close GUESTBOOK.
Now, be honest. That wasn't rough at all, was it? It was pretty much the same as writing to an email or to the thank-you page. You just wrote it to a separate file.
The Posting Page
There must be ten different methods of getting this page to exist so the script can write to it. I know how to do it through telnet, how to create it right from the script and a couple others that are just silly.
The easiest method is to do just what I said earlier. Create the page like you would any other.
I named my page "emaillog.html". You can call yours whatever you want, but whatever you choose, make sure to change out that name in the absolute path first in the script.
- Open Notepad.
- Save the blank page as "emaillog.html". Make sure the page is blank.
- FTP the blank page to the correct location
- Set the blank page's modification to 777
Now there's a page sitting there with permissions set for all to write to it.
The page will post new listings beneath the older ones. To blank the page, simply upload a new blank page in its place. The modifications remain and the page is a clean slate. Nothing to it...
Have We Done Enough?
I think we've gone about as far as we can with this guestbook stuff. To continue to add bells and whistles won't get us any farther. Just know that at this point you have the knowledge to change this script all around and back again. Hopefully, you've at least gussied up the thank-you page. Man, is that thing dull right now.
Primer Seven Assignment
Let's say you wanted to create two guestbook posts. One would be for personal messages and the other you would use to have people post messages on another topic. How would you go about setting that second post up?
This will open in a new window
[What It All Means]
[The Postings Page]