I have the following script (from previous question) and I want to modify it a little. Eventually maybe I'll be able to do this myself...but for now I need someone to rewrite it for me. The following script reads data passed by a form and spits the information back (in form format) and asks the user if it's correct...then the user submits the data again for the final time or starts over from scratch:
#!/usr/bin/perl
use CGI;
$q=new CGI;
## Send the proper MIME header to the browser.
print "Content-type: text/html\n\n";
if ($q->param){
## Read the HTML Form variables into local PERL variables.
## NOTE: the variable names are case sensitive. so fn is NOT the same as FN o
r Fn or fN.
$page=$q->param('page');
$first_name=$q->param('fn');
$city=$q->param('city');
## Find out which button the user clicked!!
$action=$q->param('action');
if ($page=~ /^1$/){
print "<B> Are you sure all the info is correct?</B><P>\n";
$page++;
}elsif ($page=~ /^2$/){
if ($action=~ /^Finish$/){ ## Finish button was clicked
print "OK!! All your info has been accepted!!<P>\n";
## Print the users info!!
print "First name is <B>$first_name</B><br>\n";
print "City is <B>$city</B><br>\n";
exit;
}elsif ($action=~ /^Start over$/){ ## Start over button clicked!!
$page=1;
$first_name="";
$city="";
}
}
}else{
$page=1 if (!$page);
}
print qq{
<B>The Basic HTML FORM</B><P>
<FORM METHOD=POST ACTION="$ENV{'SCRIPT_NAME'}">
<B>Enter name </B><input type=text name=fn value=$first_name><BR>
<B>Enter city </B><input type=text name=city value=$city><P>
<input type=hidden name=page value=$page>
};
1) I want to do away completely with the "start over" button, I'll simply give the user instructions to hit the back button on his browser to change info in the fields. The "start over" option is too cumbersome.
2) When the user is asked to verify the fields, I don't want the form to just be repeated to the user with the fields filled with the variables. I would like to have formatted text with the variables inserted so has a professional look. At the bottom of the page then, there would be the "is this info correct?" text and a submit button to finalize the submition. Basically, after the user verifies the data, it will be e-mailed to a specified address (I don't want to know how to do this yet...one step at a time).
Please include any comments in the script that will help me understand what's going on and maybe someday I'll understand this stuff.
here is the script that does both the above things for you.
for point 1 i have commented out the unwanted lines of the code, both PERL & HTML.
for point 2 i have shown the info in a HTML table. you can format the output and make it look as you want it by modifying the HTML tags. Also i have moved the confirmation Q to the bottom of the table.
Finally i have added comments to the code and also put the comment in the code indicating where the email piece is to be inserted.
==============simple.pl
#!/usr/bin/perl
use CGI;
$q=new CGI;
## Send the proper MIME header to the browser.
print "Content-type: text/html\n\n";
if ($q->param){
## Read the HTML Form variables into local PERL variables.
## NOTE: the variable names are case sensitive. so fn is NOT the same as FN o
r Fn or fN.
$page=$q->param('page');
$first_name=$q->param('fn');
$city=$q->param('city');
## Find out which button the user clicked!!
$action=$q->param('action');
if ($page=~ /^1$/){
#print "<B> Are you sure all the info is correct?</B><P>\n";
$page++;
}elsif ($page=~ /^2$/){
if ($action=~ /^Finish$/){ ## Finish button was clicked
print "OK!! All your info has been accepted!!<P>\n";
## The send out as email part of the code will go here.
# ## Print the users info!!
# print "First name is <B>$first_name</B><br>\n";
# print "City is <B>$city</B><br>\n";
exit;
# }elsif ($action=~ /^Start over$/){ ## Start over button clicked!!
# $page=1;
# $first_name="";
# $city="";
}
}
}else{
$page=1 if (!$page);
}
if ($page=~ /^1$/){ ## Print the First page i.e. HTML form.
print qq{
<B>The Basic HTML FORM</B><P>
<FORM METHOD=POST ACTION="$ENV{'SCRIPT_NAME'}">
<B>Enter name </B><input type=text name=fn value=$first_name><BR>
<B>Enter city </B><input type=text name=city value=$city><P>
<input type=hidden name=page value=$page>
<input type=submit name=action value="Submit">
</FORM>
};
}elsif ($page=~ /^2$/){ ## Show the user the info entered & seek confirmation.
print qq{
<TABLE BORDER=0 CELLSPACING=5>
<TD><B>Name</B></TD><TD>$first_name</TD>
<TR>
<TD><B>City</B></TD><TD>$city</TD>
<TR>
<TD COLSPAN=2><B>Is this info correct?</TD>
<TR>
<TD COLSPAN=2 ALIGN=CENTER>
<FORM METHOD=POST ACTION="$ENV{'SCRIPT_NAME'}">
<input type=hidden name=page value=$page>
<input type=submit name=action value="Finish">
<!--input type=submit name=action value="Start over"-->
</FORM>
</TD>
</TABLE>
};
}
for point 1 i have commented out the unwanted lines of the code, both PERL & HTML.
for point 2 i have shown the info in a HTML table. you can format the output and make it look as you want it by modifying the HTML tags. Also i have moved the confirmation Q to the bottom of the table.
Finally i have added comments to the code and also put the comment in the code indicating where the email piece is to be inserted.
==============simple.pl
#!/usr/bin/perl
use CGI;
$q=new CGI;
## Send the proper MIME header to the browser.
print "Content-type: text/html\n\n";
if ($q->param){
## Read the HTML Form variables into local PERL variables.
## NOTE: the variable names are case sensitive. so fn is NOT the same as FN o
r Fn or fN.
$page=$q->param('page');
$first_name=$q->param('fn'
$city=$q->param('city');
## Find out which button the user clicked!!
$action=$q->param('action'
if ($page=~ /^1$/){
#print "<B> Are you sure all the info is correct?</B><P>\n";
$page++;
}elsif ($page=~ /^2$/){
if ($action=~ /^Finish$/){ ## Finish button was clicked
print "OK!! All your info has been accepted!!<P>\n";
## The send out as email part of the code will go here.
# ## Print the users info!!
# print "First name is <B>$first_name</B><br>\n";
# print "City is <B>$city</B><br>\n";
exit;
# }elsif ($action=~ /^Start over$/){ ## Start over button clicked!!
# $page=1;
# $first_name="";
# $city="";
}
}
}else{
$page=1 if (!$page);
}
if ($page=~ /^1$/){ ## Print the First page i.e. HTML form.
print qq{
<B>The Basic HTML FORM</B><P>
<FORM METHOD=POST ACTION="$ENV{'SCRIPT_NAME'
<B>Enter name </B><input type=text name=fn value=$first_name><BR>
<B>Enter city </B><input type=text name=city value=$city><P>
<input type=hidden name=page value=$page>
<input type=submit name=action value="Submit">
</FORM>
};
}elsif ($page=~ /^2$/){ ## Show the user the info entered & seek confirmation.
print qq{
<TABLE BORDER=0 CELLSPACING=5>
<TD><B>Name</B></TD><TD>$f
<TR>
<TD><B>City</B></TD><TD>$c
<TR>
<TD COLSPAN=2><B>Is this info correct?</TD>
<TR>
<TD COLSPAN=2 ALIGN=CENTER>
<FORM METHOD=POST ACTION="$ENV{'SCRIPT_NAME'
<input type=hidden name=page value=$page>
<input type=submit name=action value="Finish">
<!--input type=submit name=action value="Start over"-->
</FORM>
</TD>
</TABLE>
};
}