Solved

Create a Form in CGI

Posted on 2004-05-02
8
346 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
The viewer will learn how to dynamically set the form action using jQuery.
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now