Solved

Create a Form in CGI

Posted on 2004-05-02
8
348 Views
Last Modified: 2013-12-25
Is it possible to create a Form in CGI instead of HTML and have it post to another CGI script?

Regards...
0
Comment
Question by:ziffgone
  • 4
  • 4
8 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 100 total points
ID: 10974403
Your terminology is not correct, but I do know what you are asking.

Any CGI *program* can generate HTML, which obviously includes a form.  There is no need to call another CGI script to process the form, as the same script can perform all the functions.

If you are using Perl for writing your CGI scripts, the following example shows a simple form and processing the results:

#!/usr/bin/perl
use CGI qw/:standard/;

print header,
        start_html('A Simple Form Example'),
        h1('A Simple Form Example'),
        start_form,
        "What's your name? ",textfield('name'),p,
        "What's the combination?", p,
        checkbox_group(-name=>'words',
                       -values=>['eenie','meenie','minie','moe'],
                       -defaults=>['eenie','minie']), p,
        "What's your favorite color? ",
        popup_menu(-name=>'color',
                   -values=>['red','green','blue','chartreuse']),p,
        submit,
        end_form,
        hr;   if (param()) {
       print "Your name is",em(param('name')),p,
             "The keywords are: ",em(join(", ",param('words'))),p,
             "Your favorite color is ",em(param('color')),
             hr;
   }
0
 
LVL 14

Author Comment

by:ziffgone
ID: 10974735
You are right Tintin, poor terminology.

Can you add Hidden fields to this form?

Also, I do need to send to another CGI program. I am sending the info to a third party and their CGI program would decipher what I have sent. How could I do this?

The hope here is that any hidden field can be pulled from within the CGI script and not show up in the HTML source.

0
 
LVL 48

Expert Comment

by:Tintin
ID: 10982674
You can use hidden fields just as you'd use them in a HTML file.  The Perl CGI module has HTML shortcuts, but you can write your own HTML code, eg:

print header;
print <<EOF;
<html>
...
<form action="http://www.example.com/cgi-bin/remote_script.cgi" method="post">
....
</form>
</html>
EOF

Note the form action sends the form query to the remote server.  Note, you'll need to check whether it uses GET or POST.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 14

Author Comment

by:ziffgone
ID: 10983352
Yup. Not what I'm looking for. I was looking for a way to truly hide the Hidden feilds of a form.

There is a program that comes close, Master Secret Hidden Fields at http://willmaster.com/master/secrethiddenfields/

Seems like a pretty sloppy program though given that there's better ways of doing what it does, so I'm not sure it's the way I want to go. Something along this line though.

Thanks...
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10983448
Well, if the remote CGI program uses the POST method, then you can just bundle everything up in a POST request and not worry about hidden fields.

What are you trying to hide anyway?
0
 
LVL 14

Author Comment

by:ziffgone
ID: 10985689
Trying to hide the return value in a PayPal button form for an Instant Downloadable product.

What would be the code to send this data via POST request? I have tried this before with no success.

Thanks Tintin...
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10992640
Here's an example POST request

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;  

my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse',
                [ search => 'www', errors => 0 ];  

print $ua->request($req)->as_string;
0
 
LVL 14

Author Comment

by:ziffgone
ID: 11030914
Is there a way to Send the info to the page specified instead of bringing the page content to your server?

Here is what I have right now:

CODE: ---------------------------------------------------
#!/usr/bin/perl -w

use CGI;

# delete next line before running when fixed
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;  

$req = POST 'https://www.paypal.com/cgi-bin/webscr',
                [ cmd => '_xclick', business => 'myemail@mydomain.com', item_name => 'Test_Item', item_number => '001', amount => '0.01', return => 'http://www.google.com/', cancel_return => 'http://www.google.com', no_note => '1', currency_code => 'USD' ];  

print "Content-type: application/x-www-form-urlencoded";
print $ua->request($req)->as_string;
ENDCODE: -----------------------------------------------------
For an example of what it does:
http://webmastereseller.com/cgi-bin/post.cgi

You'll see the PayPal page come up, but because the page is requested to my server, all of the images don't show etc. If you click on the Login button, the page transfers to PayPal and everything is correct.

How can I send the info to PayPal instead of bringing the PayPal page to me? Would it be a different command than "request($req)"? Something along the line of "send($req)"?

Your thoughts...
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 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