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:
2 tasks in one program

 



simon
Deleted

Aug 9, 2000, 4:44 PM

Post #1 of 4 (736 views)
2 tasks in one program Can't Post

How can i do this?
I want this script to submit to itself and then print this part
print "ICQ Number :$FormData{icq} ";
on a blank page not under the form again, if there was nothing written in the form field then it prompts the form again. How do i do this?
regards:
simon


#!/usr/bin/perl
print ("Content-type: text/html\n\n");
use CGI_Lite; # LOAD CGI_LITE To parse input from form
$InCGI = new CGI_Lite(); # Make a new CGI_Lite() Called $InCGI
@LiteCGI = $InCGI ->parse_form_data(); # Parse and assign results to Array @LiteCGI
%FormData = @LiteCGI; # Transfer @LiteCGI into Associative array %FormData
&html;
sub html
{
print <<EOF;
<form>
<tr>
<td align=right bgcolor="Silver" border=0><font face="arial" color="black"
size=2><b>ICQ
Number : </b></font></td>
<td align="LEFT" bgcolor="E6E6E6">
<input type="text" name="icq" size = 30 maxlength=50>
</td>
</tr>
<p align="center"><input type="submit" value="All Done"
name="submit">
<input type="reset" value="Reset Form" name="B2"></p>
</form>
EOF
}

print "ICQ Number :$FormData{icq} ";



Kanji
User / Moderator

Aug 10, 2000, 6:07 AM

Post #2 of 4 (736 views)
Re: 2 tasks in one program [In reply to] Can't Post

Do an if-else on whether $FormData{'icq'} contains anything ...
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if ( defined $FormData{'icq'} ) {
print $FormData{'icq'};
} else {
&html;
}</pre><HR></BLOCKQUOTE>
Also, I'm not sure why you use @LiteCGI if all you do with it is create a hash? Why not create the hash directly?

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

# Parse and assign results
%FormData = $InCGI->parse_form_data();</pre><HR></BLOCKQUOTE>


simon
Deleted

Aug 10, 2000, 8:42 AM

Post #3 of 4 (736 views)
Re: 2 tasks in one program [In reply to] Can't Post

Ok i tried the code you gave me so our code looks something like this

#!/usr/bin/perl
print ("Content-type: text/html\n\n");
use CGI_Lite; # LOAD CGI_LITE To parse input from form
$InCGI = new CGI_Lite(); # Make a new CGI_Lite() Called $InCGI
@LiteCGI = $InCGI ->parse_form_data(); # Parse and assign results to Array @LiteCGI
%FormData = @LiteCGI; # Transfer @LiteCGI into Associative array %FormData
&html;
sub html
{
print <<EOF;
<form>
<tr>
<td align=right bgcolor="Silver" border=0><font face="arial" color="black"
size=2><b>ICQ
Number : </b></font></td>
<td align="LEFT" bgcolor="E6E6E6">
<input type="text" name="icq" size = 30 maxlength=50>
</td>
</tr>
<p align="center"><input type="submit" value="All Done"
name="submit">
<input type="reset" value="Reset Form" name="B2"></p>
</form>
EOF
}
if ( defined $FormData{'icq'} ) {
print $FormData{'icq'};}
else { &html;}

but now when i try it it shows 2 rows of
Enter your icq number: Text Box
Enter your icq number: Text Box
any ideas?


Kanji
User / Moderator

Aug 10, 2000, 9:09 AM

Post #4 of 4 (736 views)
Re: 2 tasks in one program [In reply to] Can't Post

Remove the first call to &html;. No point using if-else if you're also going to run it regardless of the data check.

 
 


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

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