Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > <FORM> Submit question with perl cgi scripts

Reply
Thread Tools

<FORM> Submit question with perl cgi scripts

 
 
dogdog@noemail.com
Guest
Posts: n/a
 
      12-01-2004
Another question, guess I could start a daily question
roster since I've been posting so much lately.

Here goes.

I have my HTML document setup to submit to a cgi script.
The script passes information to my server and responds
back as it should. However, I would like to be able to
do the following:

1. Have the response post back to my original webpage and
not create a seperate page with the information.
2. If 1 is possible, I would like to have the items returned
to the original webpage placed into the textboxes that I have
setup. These boxes are used when I input information to the
server I have and hit submit.

Any way to do this ?? Would appreciate suggestions, examples
anything in relation to this.

Thanks
dogdog
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-01-2004
wrote:
> I have my HTML document setup to submit to a cgi script. The script
> passes information to my server and responds back as it should.
> However, I would like to be able to do the following:
>
> 1. Have the response post back to my original webpage and not create
> a seperate page with the information. 2. If 1 is possible, I would
> like to have the items returned to the original webpage placed into
> the textboxes that I have setup. These boxes are used when I input
> information to the server I have and hit submit.


Have the script generate the empty HTML form when invoked without
arguments, and have it include the items when invoked via the submit
button.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      12-01-2004
wrote:

> 1. Have the response post back to my original webpage and
> not create a seperate page with the information.


CGI.pm is well suited for that. By default, its methods for producing
form elements will read the values it assigns to those elements from the
incoming request.

> Any way to do this?


All is revealed in the docs for CGI.pm:

perldoc CGI

or

<http://stein.cshl.org/WWW/software/CGI/>

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
dogdog@noemail.com
Guest
Posts: n/a
 
      12-01-2004
On Wed, 01 Dec 2004 17:49:34 +0000, Sherm Pendley wrote:

> wrote:
>
>> 1. Have the response post back to my original webpage and
>> not create a seperate page with the information.

>
> CGI.pm is well suited for that. By default, its methods for producing
> form elements will read the values it assigns to those elements from the
> incoming request.
>
>> Any way to do this?

>
> All is revealed in the docs for CGI.pm:
>
> perldoc CGI
>
> or
>
> <http://stein.cshl.org/WWW/software/CGI/>
>
> sherm--

Sherm,
I was just reading about cgi.pm in the mouse or rat book
by o'reily (whatever its called). It seems this will work
but I'm still not 100 percent clear. From what I'm reading it
seems I will
still be generating a seperate html page and moving away from
my original index page? Is that true?

What about using embperl. Do I get any benefit by including
my scripts in the html? I guess I would still need cgi.pm to
generate the output html so it looks like the original page?

Ahh the questions, it would be so much easier if I was able to
see this in action on the web.

thanks and let me know if you have answers to even more of my
questions.
tia
dogdog




 
Reply With Quote
 
dogdog@noemail.com
Guest
Posts: n/a
 
      12-01-2004
On Wed, 01 Dec 2004 23:45:21 +0100, Gunnar Hjalmarsson wrote:

> wrote:
>> I have my HTML document setup to submit to a cgi script. The script
>> passes information to my server and responds back as it should.
>> However, I would like to be able to do the following:
>>
>> 1. Have the response post back to my original webpage and not create
>> a seperate page with the information. 2. If 1 is possible, I would
>> like to have the items returned to the original webpage placed into
>> the textboxes that I have setup. These boxes are used when I input
>> information to the server I have and hit submit.

>
> Have the script generate the empty HTML form when invoked without
> arguments, and have it include the items when invoked via the submit
> button.

Gunnar,
Sorry to sound dense on this but I'm not very up to speed as
it is. I dont understand what your saying by empty HTML. Could
you elaborate.

tks
dogdog
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-02-2004
wrote:
> Gunnar Hjalmarsson wrote:
>> wrote:
>>> I have my HTML document setup to submit to a cgi script. The
>>> script passes information to my server and responds back as it
>>> should. However, I would like to be able to do the following:
>>>
>>> 1. Have the response post back to my original webpage and not
>>> create a seperate page with the information. 2. If 1 is possible,
>>> I would like to have the items returned to the original webpage
>>> placed into the textboxes that I have setup. These boxes are used
>>> when I input information to the server I have and hit submit.

>>
>> Have the script generate the empty HTML form when invoked without
>> arguments, and have it include the items when invoked via the
>> submit button.

>
> Sorry to sound dense on this but I'm not very up to speed as it is. I
> dont understand what your saying by empty HTML. Could you elaborate.


Okay, here is a quick-and-dirty script to illustrate the idea:

#!/usr/bin/perl -T
use strict;
use warnings;
use CGI 'escapeHTML';
use File::Basename;

my $script = basename $0;
my $q = new CGI;
my %in = $q->Vars;
for ('name', 'age') {
$in{$_} ||= '';
$in{$_} = escapeHTML $in{$_};
}

print $q->header;
print <<HTML;
<html>
<body>
<form action="$script" method="post">
Name: <input type="text" name="name" value="$in{name}"><br>
Age: <input type="text" name="age" value="$in{age}"><br>
<input type="submit">
</body>
</html>
HTML

__END__

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      12-02-2004
wrote in
news:

> Ahh the questions, it would be so much easier if I was able to
> see this in action on the web.


There is no point in trying to do CGI development without a proper test
bed. Install Apache or another comparable web server on your development
system along with Perl and try out the examples.

And please try to keep your posts on topic. Have you read the posting
guidelines for comp.lang.perl.misc?

--
A. Sinan Unur
d
(remove '.invalid' and reverse each component for email address)

 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      12-02-2004
wrote:

> I was just reading about cgi.pm in the mouse or rat book
> by o'reily (whatever its called).


They call it a mouse. I like your rat idea better.

> still be generating a seperate html page and moving away from
> my original index page? Is that true?


Yeah - there's really no way around that with CGI. You can't modify the
page in-place, all you can do is send a new page.

What you *can* do though, is send a page that's virtually identical to
the one with the form.

> Ahh the questions, it would be so much easier if I was able to
> see this in action on the web.


Here's a simple example:

#!/usr/bin/perl -T
use strict;
use warnings;
use CGI;

my $q = new CGI;

print $q->header;

my $formtag = $q->start_form;
my $nametag = $q->textfield('name');

print <<HTML;
<html>
<body>
$formtag
What's your name? $nametag<br>
<input type="submit">
</body>
</html>
HTML

When you use the textfield() method above, it looks for an input named
'name' in the query. If it finds one, it uses it to generate a value=""
attribute for the <input ...> element.

Similarly, the start_form() method produces a <form ...> element with an
action="" method that refers back to this script.

That's the basic idea - the CGI.pm methods that produce form elements
take the values assigned to those elements from the form input. This
makes it easy to build self-referential forms like you're describing.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
dogdog@noemail.com
Guest
Posts: n/a
 
      12-02-2004
On Wed, 01 Dec 2004 20:40:56 +0000, Sherm Pendley wrote:

> wrote:
>
>> I was just reading about cgi.pm in the mouse or rat book
>> by o'reily (whatever its called).

>
> They call it a mouse. I like your rat idea better.
>
>> still be generating a seperate html page and moving away from
>> my original index page? Is that true?

>
> Yeah - there's really no way around that with CGI. You can't modify the
> page in-place, all you can do is send a new page.
>
> What you *can* do though, is send a page that's virtually identical to
> the one with the form.
>
>> Ahh the questions, it would be so much easier if I was able to
>> see this in action on the web.

>
> Here's a simple example:
>
> #!/usr/bin/perl -T
> use strict;
> use warnings;
> use CGI;
>
> my $q = new CGI;
>
> print $q->header;
>
> my $formtag = $q->start_form;
> my $nametag = $q->textfield('name');
>
> print <<HTML;
> <html>
> <body>
> $formtag
> What's your name? $nametag<br>
> <input type="submit">
> </body>
> </html>
> HTML
>
> When you use the textfield() method above, it looks for an input named
> 'name' in the query. If it finds one, it uses it to generate a value=""
> attribute for the <input ...> element.
>
> Similarly, the start_form() method produces a <form ...> element with an
> action="" method that refers back to this script.
>
> That's the basic idea - the CGI.pm methods that produce form elements
> take the values assigned to those elements from the form input. This
> makes it easy to build self-referential forms like you're describing.
>
> sherm--


I thought that sending a somewhat identical page was what you were
eluding to. I'll read over more in the book and use your
example. Thanks alot for that its a great help.

dogdog

 
Reply With Quote
 
dogdog@noemail.com
Guest
Posts: n/a
 
      12-02-2004
On Wed, 01 Dec 2004 16:16:35 +0000, Jim Gibson wrote:

> In article <>,
> <> wrote:
>
>> On Wed, 01 Dec 2004 23:45:21 +0100, Gunnar Hjalmarsson wrote:
>>
>> > wrote:
>> >> I have my HTML document setup to submit to a cgi script. The script
>> >> passes information to my server and responds back as it should.
>> >> However, I would like to be able to do the following:
>> >>
>> >> 1. Have the response post back to my original webpage and not create
>> >> a seperate page with the information. 2. If 1 is possible, I would
>> >> like to have the items returned to the original webpage placed into
>> >> the textboxes that I have setup. These boxes are used when I input
>> >> information to the server I have and hit submit.
>> >
>> > Have the script generate the empty HTML form when invoked without
>> > arguments, and have it include the items when invoked via the submit
>> > button.

>> Gunnar,
>> Sorry to sound dense on this but I'm not very up to speed as
>> it is. I dont understand what your saying by empty HTML. Could
>> you elaborate.

>
> You don't seem to have understood Gunnar's and Sherm's answers, so
> there seems to be a conceptual disconnect. I will try to fill in some
> of the blanks, although I will simplify somewhat.
>
> You cannot in general add information to a web page that is already
> displayed in your browser. (The exceptions are if you have a Java
> applet, Javascript, or other browser-based method dynamically changing
> the appearance of the web page.) It sounds like you have a static home
> page (index.html) that contains a form, which you would like to submit
> to a server. It is not clear if this server is the web server or
> another, secondary server. You then want to get a response from this
> server that the browser uses to modify the form elements or other
> elements on the page.
>
> What you can do is have your cgi program return a page that looks
> exactly like your static home page with the form response information
> included therein. Then it will appear as if your page has been updated
> using your server response.
>
> If that is what you want, you can take it one step further and arrange
> to have your original home page generated by the same cgi program. This
> is what Gunnar means by an empty HTML. The first time the page is
> fetched and displayed, the forms elements are empty. If you get fancy,
> you can fill them with default values or the values from a previous
> fetch.
>
> Please understand that this problem has little to do with Perl, and is
> the same regardless of the language you use to implement the cgi
> program. There are HTML groups to discuss this sort of thing. However,
> Perl's CGI module is ideal for this sort of thing, hence Sherm's
> recommendation to use it.
>
> HTH.

Jim,
Thanks for your clarification on this. I went to the perl group
first because I was hoping that there was something in perl
that could be done outside of the html range of things
(i.e. fancy scripting tricks that are similiar to javascript
type page in place actions).
Thanks again for your clarification. Gunnar has also
submitted some samples in reference to what he was speaking of
earlier. Which I'm sure will be quite beneficial.
dogdog
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Python Scripts with IIS - ASP or Python-based CGI scripts withIIS - which makes more sense? davidj411 Python 0 06-27-2008 04:38 PM
What is required for perl scripts to run correct when launched from rc scripts on HPUX 11? deanjones7@gmail.com Perl Misc 13 09-10-2007 11:58 AM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
File Creation Problem with CGI Scripts in Apache cgi-bin (Fedora Core 3) BestFriend Perl Misc 2 08-21-2006 04:02 PM
CGI Programmers needed to hack around at our CGI Scripts James Perl Misc 1 08-04-2003 09:27 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57