View Full Version : perl--> how to send the input from a form to another script
instruction
10-10-2002, 05:41 PM
I have a form that uses method = POST. Once the user hits the "submit" button I have a script that checks the data for accuracy. However after I check the users input I want to send the data to a cgiemail script. HOW DO I send the the original input (that came in the STDIN) to the next form? thank you for helping if you can;).
sheila
10-10-2002, 06:47 PM
This looks like it might have a clue:
http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_20145281.html
Good luck!
-- google is my best friend! ;)
sheila
10-10-2002, 06:50 PM
But wait! There's more!
http://discuss.cgi101.com/cgi101/article.cgi?8335
http://www.ku.edu/~acs/docs/other/forms-intro.shtml#target8
:look:
instruction
10-12-2002, 08:44 AM
Shiela,
Thank you for the links. They tought me some things I did not know, and I appreciate that. However the examples given in those tutorials, assume that you know the "VALUE" of the variables. For instance say you assigned the variable name --> f_name to the "what is your first name:" field of a form. When the user types in whate there name is, I nor my program know what the value of f_name is: Well I do, but the examples all use literal strings, so You can not put something like:
f_name => '$form{\'required-f_name\'}'; :\
That is not literal. So how would I get the literal string---> say they typed:
freddy. <---how do you get your program to come up with the literal string rather then haveing it assigned to a variable?
Any ideas? This probably made no since, and if it doesn't I am sorry. %)
sheila
10-12-2002, 10:40 AM
Originally posted by instruction:
However the examples given in those tutorials, assume that you know the "VALUE" of the variables. For instance say you assigned the variable name --> f_name to the "what is your first name:" field of a form. When the user types in whate there name is, I nor my program know what the value of f_name is: Well I do, but the examples all use literal strings, so You can not put something like:
f_name => '$form{\'required-f_name\'}'; :\
That is not literal. So how would I get the literal string---> say they typed:
freddy. <---how do you get your program to come up with the literal string rather then haveing it assigned to a variable?
Any ideas? This probably made no since, and if it doesn't I am sorry. %)
k, let me answer your question with a question. :P
Doesn't your verification script know the key/value pairs for the data submitted by the form? For example
required-f_name = freddy
right?
Isn't "required-f_name" the name in the form for the field where they enter the first name, and the value entered would be something like "freddy"?
But you are saying, if I understand you correctly, that you don't know "freddy"? Then I don't understand how you are validating the data with the previous step? How can the validation script do it's thing if it only has $form{\'required-f_name\'} instead of "freddy" ?
This is the information you need to pass to cgiemail after you've validated the data?
So, it looks to me, from the lwpcookbook (linked from one of the references above) that once you've validated the data, your validation script could pass it on to cgiemail as follows:
(see the section on POST in the lwpcookbook (http://www.perldoc.com/cpan/lwpcook.html#POST))
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
my $req = POST 'http://www.yourdomain.com/cgi-bin/cgiemail/template.txt',
[ required-f_name => 'freddy', required-l_name => 'smith' ];
print $ua->request($req)->as_string;
I'm not sure, but maybe this would work also (I would think so?):
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
my $req = POST 'http://www.yourdomain.com/cgi-bin/cgiemail/template.txt',
[ required-f_name => $form{\'required-f_name\'},
required-l_name => $form{\'required-l_name\'} ];
print $ua->request($req)->as_string;
I can't see why the above wouldn't work, in the case that you don't know the actual values from the form. However, I won't be testing it for you, as I don't program in Perl. (Mostly use Python at the moment.) Anyhow, I hope the above is right. I would suggest testing it out and seeing what happens. Or, maybe some of the Perl experts will come in here and double-check/verify the above. I'm really more comfortable discussing Python. (I already looked to see that Python can also do this, see http://www.python.org/doc/current/lib/module-urllib2.html . So, I have learned something useful for me, as well. ;) )
[edit: I know I have made syntax errors in the above with misplaced quote marks, or not escaping certain characters. I think the meaning is clear though? I'm loathe to try and do much correcting, since I'm not really sure of the correct syntax anyhow.]
instruction
10-12-2002, 11:13 AM
starting where you wrote:
required-f_name = freddy
yes my verification script know the value. However what is not possable is this:
[ required-f_name => 'freddy', required-l_name => 'smith' ]
nor this:
required-f_name => $form{'required-f_name'}
the first one assumes that I am there to tell the script the name--well I wont be there when they fill out the form.
the second will literaly send --> $form{'required-f_name'} rather then the value it represents. See that is where the problem is! Whatever comes after the => is literal---in other words will be printed (or sent) as is!
See what I can not figure out is this:
I take the <STDIN> and break it down (you know decode the url encodeing) then the $form{'required-f_name'} can be assigned to a variable, but I do not know how to tell the script that I do not want to assign it to anything, but rather I want the VALUE ITSELF. The script when useing => has to have the value--yes I myself can get the value printed to screen, but how do I get the script to figure out the value and send that value not a variable representing the value?
I hope that makes since. I do not know to much about python, but I sure do appreciate all your help. Thank you
by the way all of the following is correct:
Doesn't your verification script know the key/value pairs for the data submitted by the form? For example---------> Yes
required-f_name = freddy---------->yes
right?
Isn't "required-f_name" the name in the form for the field where they enter the first name, and the value entered would be something like "freddy"?-->yes
But you are saying, if I understand you correctly, that you don't know "freddy"? ----> find out but how does the script know this so that it can send that rather then $form{'required-f_name'}<----that is what will be sent not the value becuse it comes after the =>
sheila
10-12-2002, 11:18 AM
Hmm. I'm afraid that answering your question requires a bit more knowledge of Perl than I have. I'm sure it is possible to do what you want. Hopefully someone who knows Perl will come along soon and take a try at answering your question.
Good luck,
instruction
10-12-2002, 11:22 AM
thank you shiela for all your help
instruction
10-12-2002, 01:52 PM
Would still like to know how to do what I asked at first. So if you know I would glady accept the help. I have deicided to make a jump page to temperarly allow the scriot to work. In other words I decided to create another form with hidden fields where the user has to hit continue. It will then post it to cgiemail. However I would still like to know how to post the values from one form to another form. Thanks in advance to anyone who can help.
skolnick
10-12-2002, 02:12 PM
required-f_name => $form{'required-f_name'}
I'm surprised this doesn't work. I'm loaded up this weekend, but when I clear my backlog I'll take a look, unless another Perl afficionado wanders by first.
kitchin
10-12-2002, 03:42 PM
My testing shows some quotes are required:
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
my $req = POST 'http://www.yourdomain.com/cgi-bin/cgiemail/template.txt',
[ 'required-f_name' => $form{'required-f_name'},
'required-l_name' => $form{'required-l_name'} ];
print $ua->request($req)->as_string;
'required-f_name' => blahblah
otherwise it sends
0 => blahblah
instruction
10-14-2002, 07:56 PM
Thank you kitchen. And sheila sorry for spelling your name wrong.
vBulletin® v3.6.8, Copyright ©2000-2013, Jelsoft Enterprises Ltd.