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: [Solved]Post form and response on same page: Edit Log



dunsta
Novice

May 19, 2013, 12:02 AM


Views: 206
[Solved]Post form and response on same page

Solved, I found I needed an ';' after the html 'p' in the else section.

Hi

I would like to be able to post the response on a 'clean' page, i.e. without the initial form.

Currently my code looks like this:

Code
#!c:/wamp/bin/perl/bin/perl.exe 

use warnings;
use strict;

use CGI qw(:all);

print
header(),
start_html("Form and Response in one"),
start_form,
h1("Submitted Information"),
"Field 1", textfield('field1'),p,
"Field 2", textfield('field2'),p,
submit, reset,
hr,
end_form;


if(param()){
my @names = param();

foreach(@names){
print p(b($_), " ", param($_));
}

}

print end_html();


but if I put the @names = params() in the else, the script prints 'field1' and 'field2'.


Code
#!c:/wamp/bin/perl/bin/perl.exe 

use warnings;
use strict;

use CGI qw(:all);

unless(param()){
print
header(),
start_html("Form and Response in one"),
start_form,
h1("Submitted Information"),
"Field 1", textfield('field1'),p,
"Field 2", textfield('field2'),p,
submit, reset,
hr,
end_form;
}else{

print
header(),
start_html("head"),
h2("Info goes here"), p,
my @names = param();
foreach(@names){
print p(b($_), " ", param($_));
}

}


so I tried putting the @names declaration above the unless, but I am not sure why the script does not run this way:


Code
#!c:/wamp/bin/perl/bin/perl.exe 

use warnings;
use strict;

use CGI qw(:all);
my @names = param();

unless(@names){
print
header(),
start_html("Form and Response in one"),
start_form,
h1("Submitted Information"),
"Field 1", textfield('field1'),p,
"Field 2", textfield('field2'),p,
submit, reset,
hr,
end_form;
}else{

print
header(),
start_html("head"),
h2("Info goes here"), p,
#my @names = param();
foreach(@names){
print p(b($_), " ", names($_));
}

}

print end_html();


Thanks for any input.


(This post was edited by dunsta on May 19, 2013, 12:11 AM)


Edit Log:
Post edited by dunsta (Novice) on May 19, 2013, 12:11 AM


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

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