View Full Version : Trying to figure out how to process a form to return an HTML page.
Pete7000
03-21-2005, 09:10 AM
Hi, I have a simple form HTML script that lists the 50 states in the typical drop-down format. The problem I'm having is this. I want the user to select a state, have the submit button send the selection to the CGI bin, and have the selection from the form processed in such a way that the correct HTML page for that state is returned. This is simple to do with HTML hyperlinks but I have no idea how to code the actions in Perl. Any help, sample script, exact terms needed to search for such a script, etc. would be greatly appreciated.
Thanks,
Pete
mlseim
03-21-2005, 02:15 PM
Pete,
It's easy to do ...
but first, give us a link to your form (with the options) so we
can see what variables you use.
Then, how you name your 50 HTML files will make a big difference.
for instance, if your form options have values like, ma,ca,co,id,wi
(two-letter state codes), then you should name each
of your individual HTML files "ma.html","ca.html","co.html" ... etc.
this would REALLY make things easy because the Perl script can
create the filename from the options variable.
So, a link to your form, and examples of the final result ...
some names of HTML files, whether there are 50 of them,
or you have grouped them somehow. We'll give you back a script
to use.
-----------------
EDIT- added
I forgot to ask whether you've installed a Perl script before.
You know it has to be uploaded into the cgi-bin in ASCII mode.
Then, permissions need to be set (CHMOD to a value of 755).
This is all done with your FTP program.
.... and
You have your options list where you select a state, then push
the submit button. If you want, the submit could be automatic
when the state is selected ... using a javascript. just a thought.
.
Pete7000
03-21-2005, 04:24 PM
I don't have the Web site up, so I couldn't post a link. Please cut, past and save it as Pete7000.htm or some such other temporary file so you can open it up in your browser if needed and delete it when you're done. (You probably already know this.)
I like the submit button probably better than a Java script auto-select because it gives the user a chance to check the selection before proceeding.
Yes, this would be the first CGI use for me and I did recall something about the need to make such settings in the CGI bin when I load the script. Thanks for the reminder!
The HTML page I would like the submit selection to return would be a similar form as the States form, only this one would be a drop down form of all the cities in that state and some selected information in text regarding the state choosen. I can cod all of that no problem, I just can't seem to get from the State Form to the HTML page that will list the cities.
Thanks for your help,
Pete.
P.S. I posted last night my time and went to bed. Checked post first thing this morning. Just wanted to let you know I always check my posts and do not jump from forum to forum and ignore those who reply if I get an answer someplace else.
______________________________________________________
<p align="left"><!--webbot bot="HTMLMarkup" startspan --> <TR>
<TD class=locationsearch align="right">
State:
</TD>
<TD>
<select onKeyDown="SubmitIfEnter(this.form);" name="STATE" size=1 ><option value="">Select a state...
<option value="AL">Alabama
<option value="AK">Alaska
<option value="AZ">Arizona
<option value="AR">Arkansas
<option value="CA">California
<option value="CO">Colorado
<option value="CT">Connecticut
<option value="DE">Delaware
<option value="DC">District of Columbia
<option value="FL">Florida
<option value="GA">Georgia
<option value="HI">Hawaii
<option value="ID">Idaho
<option value="IL">Illinois
<option value="IN">Indiana
<option value="IA">Iowa
<option value="KS">Kansas
<option value="KY">Kentucky
<option value="LA">Louisiana
<option value="ME">Maine
<option value="MD">Maryland
<option value="MA">Massachusetts
<option value="MI">Michigan
<option value="MN">Minnesota
<option value="MS">Mississippi
<option value="MO">Missouri
<option value="MT">Montana
<option value="NE">Nebraska
<option value="NV">Nevada
<option value="NH">New Hampshire
<option value="NJ">New Jersey
<option value="NM">New Mexico
<option value="NY">New York
<option value="NC">North Carolina
<option value="ND">North Dakota
<option value="OH">Ohio
<option value="OK">Oklahoma
<option value="OR">Oregon
<option value="PA">Pennsylvania
<option value="RI">Rhode Island
<option value="SC">South Carolina
<option value="SD">South Dakota
<option value="TN">Tennessee
<option value="TX">Texas
<option value="UT">Utah
<option value="VT">Vermont
<option value="VA">Virginia
<option value="WA">Washington
<option value="WV">West Virginia
<option value="WI">Wisconsin
<option value="WY">Wyoming
</select>
</TD>
</TR>
<TR>
<TD class=locationsearch vAlign=top>
</TD>
<TD colSpan=3>
<INPUT class=searchbox title="Click here to submit your search." type=submit value=Search>
</TD>
</TR>
</TBODY>
</TABLE>
mlseim
03-21-2005, 05:40 PM
Pete,
In the page with your form, you would have a <form> tag that calls
the Perl script ... something like this:
<FORM ACTION="http://www.mysite.com/cgi-bin/states.pl" METHOD="POST">
Not knowing the filenames or paths you have, I made comments
in the script below for you to customize ... and to learn how it works.
Here is the perl script, called "states.pl"
==========================================================
#! /usr/bin/perl
# These line bring in the variable from your form.
use CGI ':standard';
my $state = param('STATE');
# This line adds ".html" to the variable.
# if you are using .htm instead of .html, change it to ".htm"
$state_page = $state.".html";
# Assuming your cgi-bin is a subdirectory of the directory
# where you have all of your state HTML pages. So, you need
# to alter the path ... where "../" means to go back one
# directory from where you are (currently in the cgi-bin).
$page = "../".$state_page;
# This part is used for testing the name of the file.
# Remove comment marks (#) to get a printout of the variable.
##############
#print "Content-type: text/html", "\n\n";
#print $page;
# This part jumps to the HTML page.
# Assuming the HTML pages are named like "MN.html","WI.html"
# Comment out the print line if you are using the test lines above.
##############
print "Location: $page\n\n";
#############################
Pete7000
03-21-2005, 06:56 PM
I'll need to activate a site so I can try it out. That may take 2-3 days but I'll post back when I get it working. Thanks so much. It's great to have a an example to work with and build from. I actually searched the Web for 3-days and bought 2 books but could not narrow down enough of what was needed to put this together. Mostly, the resources pointed me towards forms which send e-mails, etc and general Perl programming that was not Web related.
Thank you very much,
Pete
mlseim
03-21-2005, 08:14 PM
That sounds good.
In the FTP program you use to upload files, you'll see a
setting called BINARY/ASCII transfer mode. The HTML
files and graphics are sent via BINARY mode (the default).
Switch to ASCII mode for sending scripts to your cgi-bin.
Then, look for the "permissions" setting, or CHMOD.
Put in a value of 755 for the script that you upload.
The very first line of the script (called the "shebang"),
#! /usr/bin/perl
is the most common. Your webhost may have something
different though, so if the script does not execute, you
might want to try.
#! /usr/sbin/perl
#! /usr/local/bin/perl
#! /usr/local/sbin/perl
or find out what they want to see.
-------------------------------
Finally, you didn't mention what the final purpose is for your project.
You would have the ability to create a simple database text file that
Perl could read from ... and Perl would create webpages for you ...
instead of creating hundreds of static pages, the Perl script would
read information from the database, build a webpage from that data,
and display it on the user's browser. This would save you having to
make 50 pages (1 for each state), and hundreds more for cities.
You would create one text file with all the necessary data, sort of
like this:
AI|Iowa|Des Moines|something about the city|image1.jpg|
AI|Iowa|Ames|something about the city|image23.jpg|
AI|Iowa|Mason|something about the city|image44.jpg|
MN|Minnesota|St. Paul|something about the city|image12.jpg|
MN|Minnesota|Minneapolis|something about the city|image5.jpg|
etc.
The list would be made up of a line for each city, with fields
separated by pipes "|". The Perl script would open the text
file and make decisions on creating an output web page based
on input from the forms. The possibilities are endless, and
changes would only need to be made to one text file.
------
and ... you could also make your state selection using HTML mapping.
The links would call your Perl script (instead of an option menu):
http://www.catpin.com/usamap/
.
Pete7000
03-22-2005, 03:24 AM
Most of my programming experience comes from working in Basic and a little assembly (and I do mean little, enough to program something like a mouse routine). Anyway, the whole concept of communicating through a server to a CGI bin and running a database in the same or similar manner feels strange since the project is not all under one system. Exciting, but strange.
I will be real happy just to get the 50 states in HTML working but yep, there's more. I thought about the cities and where I actually do want 50 HMTL pages for the states, I sure don't want say 5000+ pages for the cities. Imagine manually loading those babies up in the FTP! So, you guessed it, for beyond the state forms, I do need to create a database that can be updated from time to time and reuturn information in the form of listings for each state. Let's say you wanted to locate a realtor in Davenpot Iowa. I wouldn't recommend moving there, but let's just use it for fun. After selecting the city, the program would access the database and return all the listings of realtors to an HTML page with names, phone numbers, a jpeg image and links, etc. Whether or not I will use Perl and CGI for the database part or use PHP and MySql instead is uncertain. My Web host is probably more in favor of PHP as I believe PHP must use less server resources (I don't think I could see him being in favor of PHP for any other reason than this, but this is just strictly my guess).
So, there you have it. I'm hoping by the time I get past this first hurdle, I will have learned a bit more so I can face this database challenge. I really appreciate your help and I really like a forum that has a lot of life to it as this one appears to have.
I'll check back in a couple of days, with some good news I hope!
Thanks a bunch,
Pete
P.S. If you live in Davenport, I have either A) Lost a new friend or B) You know exactly what I mean - LOL.
mlseim
03-22-2005, 04:10 AM
As a Minnesotan, I try to stay away from Iowa.
You're right about PHP/MySQL.
If the future looks like an extensive site with constantly
changing homes for sale, photos, etc ... you'll want to
steer yourself into the PHP/MySQL direction. You can
use MySQL with Perl, but there are more applications
and tutorials directed toward PHP.
I'm guessing there might already be realtor PHP/MySQL
applications already put together into a package for
free or very little cost ... something you can install
into your website.
But, learning Perl, PHP, whatever is always a good
thing to do ... it keeps the mind sharp.
oh ... and as far as PHP/MySQL Realtor systems go,
check out some of these (might save you some time).
http://www.google.com/search?q=PHP+MySQL+realtor+scripts&btnG=Search
FYI ...
Here's the PHP version of the Perl snippet listed in the previous posts.
This goes in the same directory as your HTML file ...
your <form> tag would look something like this:
<FORM ACTION="http://www.mysite.com/states.php" METHOD="POST">
here's the file "states.php":
========================================================
<?php
//Get the variables from the form.
$state = $_POST['state'];
//Build the URL.
$page = "./".$state.".html";
//Go there.
Header("Location: $page");
?>
.
Pete7000
03-26-2005, 04:00 AM
Installed it yesterday and made some sample HTML pages to try it out. Everything seems to work perfectly and due to the simplicity of the action, I do not anticipate any problems. I may try and experiment with the PHP script at a later date but for now, the Perl code gets the job done.
Today I wrote a small basic program that automatically genetates the 50 HTML pages and the drop down forms. I'm going to write another to add up all the cities. I'll bet there's around 30 thousand of them. A PHP MySQL database certainly seems to be the next step. I doubt there are very many webmasters that would ever want to fool with 30,000 HTML pages! (LOL - I just wrote that program and ran it. I'm a pretty estimator, the number is 30,244).
Thanks,
Pete
mlseim
03-26-2005, 06:04 AM
Pete ...
Your realtor program thing sort of reminds me of a project
I just started working on for a graphic artist ...
He wants to take advantage of the new cell phones that
have Opera browsers built-in, allowing customers to find
out when their orders are complete, exchange messages,
and other stuff.
The future of the internet will soon be expanding into
the mobile phone industry. The term used is SSR, or
(Small Screen Rendering).
This type of thing would be perfect for an industry where
customers traveling could look up realtors in various cities.
It would not replace your main "full-size" website, but be
a mini information center available on their cell phones.
Here's the beginning of my new quest:
http://www.catpin.com/ssr/
It's a work in progress .... as I'm working on some new icons
and graphics along with other screens (mini web pages).
I found the CSS template and info on the Opera Browser site.
Imagine your database being accessible by cell phones ...
--have fun, and learn PHP/MySQL --
Pete7000
03-27-2005, 08:43 PM
Things move so fast in the field of computers and quality programs made be individuals take so long to make. Planning ahead for the future is certainly a smart idea and I would guess cell phones will grab up an increasing market share. I love to see what so-called "futurist" have to predict about things like this. Anyway, I check the URL and had only one problem, it didn't size to my screen (LOL). Yep, it looks good that size and could easily be read if reduces 33%. I have a Nokia video cell phone and love it. I'm looking forward to a time when cell phones will have better PDA functions and reliable voice input. That filed (voice recognition) has improved a great deal as well over the past 10 years.
Looks like you're on to something. (If I didn't like it, I'd comment "It looks like you're on something.") LOL2. I'll have to save the URL and check back. Right now, I'm still hunting down and comparing different PHP scripts (thanks for the Google link - BTW). I' between buying something cheap and simple, so I can learn from it and customize my own script, or just buying something ready to run. The only problem there is finding what I like in a market flooded with such scripts. Also, if I like it, that doesn't mean it is sufficiently free of bugs to work effectively!
Pete
mlseim
03-27-2005, 09:01 PM
The SSR site:
It's supposed to be small (145 pixels wide).
SSR (Small Screen Rendering). If you happen to
use a cell phone simulator, you'll see what it is
supposed to look like.
I know what you mean about finding scripts ...
There are so many to choose from. Don't be
afraid to modify any you find.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.