Solved

continuation of perl+forms question

Posted on 2000-05-16
5
121 Views
Last Modified: 2010-03-05
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>
};

if ($page=~ /^1$/){
  print qq{
  <input type=submit name=action value="Submit">
  };
}elsif ($page=~ /^2$/){
  print qq{
  <input type=submit name=action value="Finish">
  <input type=submit name=action value="Start over">
  };
}

print qq{
</FORM>
};

exit;

======================================

What I would like to change is this:

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.

Thank you!

0
Comment
Question by:GorGor1
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
Comment Utility
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>
  };
}

0
 
LVL 1

Author Comment

by:GorGor1
Comment Utility
When I run the script, page1 shows up and asks for the fields to be entered.  When I view the source of that page, it shows up as:

<B>The Basic HTML FORM</B><P>
<FORM METHOD=POST ACTION="/cgi-bin/simple.pl">
<B>Enter name </B><input type=text name=fn value=><BR>
<B>Enter city </B><input type=text name=city value=><P>
<input type=hidden name=page value=1>
<input type=submit name=action value="Submit">
</FORM>

Why is the "value" for name and city blank?  Is this normal?
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
".....Why is the "value" for name and city blank?  Is this normal? ...."


yes its normal for the value to be blank, since its the very first page where the user will enter the requried info.

this is a remenant of the "Start over" button.

you can as well eliminate the value= part.

Rgds
0
 
LVL 1

Author Comment

by:GorGor1
Comment Utility
Thank you very much...I will post a continuation question soon.  (Need more tweaking).
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
sure. i will try to answer it to the best of my abilities.

Rgds
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now