pisteador has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, recently I've been trying to do a perl script to automate a form POST on a coldfusion server, however I don't know if the variables are treated in a diferent way than in a CGI script, this is the code I've been using and the HTML data. The important tags of html:
<input type="radio" name="KompressorVote" value="220"> <input type="radio" name="KompressorVote" value="221"> <form action="results.cfm" method="post" name="KompressorPollsForm" id +="KompressorPollsForm"><input type="hidden" name="kact" value="">
Also, I've noticed another that there's javascript involved in this mess:
<a href="javascript:applyVotes()"><img src="el/submit_button.gif" alt= +"Accept" border="0"></a> <script language="JavaScript"> function applyVotes() { window.open ("","ApplyVote","width=400,height=300,toolbar=no,locat +ion=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhisto +ry=no"); document.KompressorPollsForm.target = "ApplyVote" document.KompressorPollsForm.action = "results.cfm" document.KompressorPollsForm.kact.value = "applyVote" document.KompressorPollsForm.submit(); } function showLastPoll() { window.open ("","ApplyVote","width=400,height=300,toolbar=no,locat +ion=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhisto +ry=no"); document.KompressorPollsForm.target = "ApplyVote" document.KompressorPollsForm.action = "results.cfm" document.KompressorPollsForm.kact.value = "showLastPoll" document.KompressorPollsForm.submit(); } </script>
So, what I'm trying to do is to POST the value "220" into results.cfm, so that it gets registered, with no success though, all I get is the same webpage where I'm supposed to select an option. This is the code I've been using:
#!/usr/bin/perl use HTTP::Request::Common qw(POST); use LWP::UserAgent; $var1="220"; $button="kact"; $ua=LWP::UserAgent->new(); my $req= POST 'http://somesite.com/results.cfm', [var1=> $var1,button= +>$button]; $content=$ua->request($req)->as_string; print $content; print $req;
I'm confused right now, afaik this should work.. Any ideas guys?.. Thanks a lot in advance :)

Replies are listed 'Best First'.
Re: Form post with Coldfusion
by dorward (Curate) on Mar 23, 2005 at 12:17 UTC

    An HTTP POST request is an HTTP POST request, there is no reason for the client to care how the server goes about working out what to respond with.

    I've never needed to submit form data with LWP, but it looks like you should be using "KompressorVote" and not "var1" since that is the name of the form control. I'd also have expected that to be a hash ref rather than an array ref.

Re: Form post with Coldfusion
by perlfan (Parson) on Mar 23, 2005 at 17:55 UTC
    This may be a dumb observation, but is your HTML form code right?

    Shouldn't:
    <input type="radio" name="KompressorVote" value="220"> <input type="radio" name="KompressorVote" value="221"> <form action="results.cfm" method="post" name="KompressorPollsForm" id +="KompressorPollsForm"><input type="hidden" name="kact" value="">
    Be:
    <form action="results.cfm" method="post" name="KompressorPollsForm" id +="KompressorPollsForm"> <input type="radio" name="KompressorVote" value="220"> <input type="radio" name="KompressorVote" value="221"> <input type="hidden" name="kact" value=""> </form>
    As stated before, and HTTP POST is an HTTP POST. If you send it correctly to "results.cfm", it doesn't matter how it was generated. "results.cfm" should access the values like all good CFM scripts do.
Re: Form post with Coldfusion
by cbrandtbuffalo (Deacon) on Mar 23, 2005 at 21:22 UTC
    Are you trying to "rock the vote," or is this just for testing?

    If Javascript is the only way to submit the form, you may not be able to script it without a tool that can understand Javascript (i.e., a full browser).