Solved

Create a Form in CGI

Posted on 2004-05-02
8
347 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to count json data 2 66
Perl script to find new files and compress those new files 5 78
home folder path for users 4 56
Adjust the position 3 45
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

948 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

21 Experts available now in Live!

Get 1:1 Help Now