Solved

Create a Form in CGI

Posted on 2004-05-02
8
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

756 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