CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
viewprofile.cgi

 



hotguy04
New User

Feb 15, 2015, 3:36 PM

Post #1 of 2 (2236 views)
viewprofile.cgi Can't Post

Hello,
Can some one help me to fix my code, i just start learning perl.
I want to display my form data on same browser page after submitting.
here is my code:
#!/usr/bin/perl
use CGI qw(:standard);

$usrn = param("username");

$pass = param("password");

$postback = param("postback");

unless ($usrn eq "username" && $pass eq "password") {

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

print "<html>";
print "<head>";
print "<title>auth.pl</title>";
print "</head>";
print "<body>";
print "<BR><BR>";

print "<form name='auth' action='auth.pl' method='post'>";
print "Username: <input type='text' name='username'>";
print "<BR><BR>";
print "Password: <input type='password' name='password'>";
print "<BR><BR>";
print "<input type='submit' value='Submit'>";
<input type='hidden' name='postback' value='1'>;
print "</form>";
print "</body>";
print "</html>";
if($postback > 0){
print "Login Error";
}
}else{
print "Content-type: text/html\n\n";
print "<html>";
print "<head>";
print "<title>auth.pl</title>";
print "</head>";
print "<body>";
print "<BR><BR>";
print "<form name='auth' action='viewprofile.cgi' method='post'>";
print "Username: <input type='text' name='username'>";
print "<BR><BR>";
print "First name: <input type='text' name='firstname'>";
print "<BR><BR>";
print "Last name: <input type='text' name='lastname'>";
print "<BR><BR>";
print "Birth date: <input type='text' name='birthdate'>";
print "(MM/DD/YYYY)<BR><BR>";
print "Country:
<select>
<option value='can'>Canada</option>
<option value='usa'>United State of America</option>
<option value='mex'>Mexico</option>
</select>";
print "<BR><BR>";
print "Street Add: <input type='text' name='streetadd'>";
print "<BR><BR>";
print "City: <input type='text' name='city'>";
print "<BR><BR>";
print "State / Prov: <input type='text' name='state/prov'>";
print "<BR><BR>";
print "ZIP / Postal: <input type='text' name='zip/postal'>";
print "<BR><BR>";
print "Home: <input type='text' name='home'>";
print "<BR><BR>";
print "Mobile: <input type='text' name='mobile'>";
print "<BR><BR>";
print "Email: <input type='text' name='email'>";
print "<BR><BR>";
print "About me: <textarea name='aboutme' cols='50' rows='5'> </textarea>";
print "<BR><BR>";
print "Photo upload: <input type='file' name='photoupload'>";
print "<BR><BR>";
print "<input type='submit' formaction='viewprofile.cgi' value='Submit'>";
print "<input type='reset' value='Reset'>";
print "</form>";
print "</body>";
print "</html>";
}


Zhris
Enthusiast

Feb 16, 2015, 1:20 PM

Post #2 of 2 (2224 views)
Re: [hotguy04] viewprofile.cgi [In reply to] Can't Post

Hi,

There are major improvements you could make to your code but for now I am just going to answer your query of "I want to display my form data on same browser page after submitting". You have fetched form data via CGI's param, i.e. username, password and postback, and assigned them to the variables $usrn, $pass, $postback respectively. You can fetch all form data in a similar manner and then its up to you how you use the variables. If for example you want to re-populate the username field with the current username value upon failure, place $usrn anywhere in your double quoted print statement and it will interpolate. It is also a good idea to check values from param are defined ( to prevent "use of uninitialized value in concatenation" warning IF you were using warnings ) and html escape them before printing ( to prevent accidental html markup breakage ).


Code
$usrn = param("username"); 
$usrn = '' unless defined $usrn;

...

$usrn = escapeHTML( $usrn );
print "Username: <input type='text' name='username' value='$usrn'>"


Chris


(This post was edited by Zhris on Feb 16, 2015, 1:24 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives