Click to See Complete Forum and Search --> : amend guestbook results to different pages


shayta
04-22-2003, 12:41 AM
I'm trying to add a feature to my site, similar to a guestbook, except rather then the output of the guestbook be all on one page, the results of the guestbook are amended to different pages (either already created, or newly created by the guestbook - if this is possible) based on the visitors respones in the guestbook submission.

For example, if one of the fields in the guestbook is what state the visitor is from, how can his/her guestbook submission be ammended to a page for his state. In other words, there would be 50 pages for each state. Does this make sense?

Also, the server I'm using only allows cgi/perl, not ASP. They support formmail, which is what I am currently using. If this can't be done in cgi/perl, can it be done any other way? Javascript? ASP?

shayta
04-24-2003, 11:53 AM
So... does anyone know how to do this?

jeffmott
04-24-2003, 12:55 PM
If you want a script that is already made for you then you can look at http://cgi.resourceindex.com

If you're looking to write your own then you'll have to ask a question more specific than "I need a script". Where are you having problems?

shayta
04-24-2003, 03:36 PM
So far I've found a couple perl files. One file (form_script.pl) is a form that asks for a visitors input and POSTS this info to an already created file (save_file.pl). save_file.pl, then opens the already created names_file.txt and appends each visitors info here. Here's the code for both files...

FORM_SCRIPT.PL...

#!/usr/bin/perl
#form_script.pl
print "Content-type:text/html\n\n"; #Content Header

print <<End_of_Doc;
<html>
<head><title>Sample Form</title></head>
<body>
<form method="POST" action="save_file.pl">
<pre>
Enter First Name:<input type="text" name="first" size="20">
Enter Last Name:<input type="text" name="last" size="20">
Select State:<SELECT name="strBudget">
<OPTION value=0 label="state">Choose
State</OPTION>
<OPTION value="CA" label="state">CA</OPTION>
<OPTION value="HI" label="state">HI</OPTION>
<OPTION value="NY" label="state">NY</OPTION>
<OPTION value="AZ" label="state">AZ</OPTION>
</SELECT>
<input type="submit" value="Submit"><input type="reset">
</pre>
</form>
</body>
</html>
End_of_Doc



and here's the code in SAVE_FILE.PL...

#!/usr/bin/perl
#save_file.pl
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
$buffer =~ tr/+/ /;
$buffer =~ s/\r/ /g;
$buffer =~ s/\n/ /g;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}
$first=$formdata{'first'};
$last=$formdata{'last'};
$state=$formdata{'strBudget'};

open(INFO, ">>names_file.txt"); # Open for appending
print INFO "$last|$first|$state\n";
close (INFO);


print "Content-type:text/html\n\n"; #Content Header

print <<End_of_Doc;
<html>
<head><title>Sample Response Page</title></head>
<body>
Thank you: $first $last from $state
</body>
</html>
End_of_Doc


What I'm looking to do is instead of save_file.pl appending everyones form input to the same file (done in this part of the code I'm assuming...

open(INFO, ">>names_file.txt"); # Open for appending
print INFO "$last|$first|$state\n";
close (INFO);

), I'm trying to amend their info to a different .txt file based upon their response to the state selection. For example, if they selected "NY" from the drop down menu in form_script.pl, is there a way to pass this ($state=$formdata{'strBudget'}; ) to the open for appending code just above? Maybe something like...

open(INFO, ">>" && $state && ".txt"); # Open for appending
print INFO "$last|$first|$state\n";
close (INFO);

Is it possible for CGI to create a new file on the server like this? Or would I have to already have a "NY.txt" file, for example, already created?

I'm new to CGI so I'm sure my syntax is off, but hopefully you get the idea of what I'm shooting for.


Shay

ideashop
08-16-2006, 02:42 AM
:) I would like to recommend www.dotcom-mute.com for hassle-free transport services

Urselc
12-27-2011, 07:53 PM
Good night, sleep tight, don't let the bedbugs bite. http://s-and-e.ru/forum/profile.php?mode=viewprofile&u=70288