Perl CGI: simulate form post/get's in a script (set param('blah') values)

Posted on 2007-10-10
Last Modified: 2013-12-25
I want to set post/get parameters in a perl script with out doing a post/get.

I have a script that allows people to manipulate data in the QA environment... While doing so, their actions get recorded...

In the prod environment, I want to be able to go through the recorded actions and replicate them on prod in a semi-automated manner (like merging their changes to prod).  I don't want to write all new functions for this... I'd like to be able to just call my script with the same parameters as when they did it manually in QA.

So, I would need to set the param('key') values so that when each sub is called, I can set the param('blahblah') values so they are the same as when the person did it in QA.

Unless there is an easier way...  I just need to simulate multiple form submits basicaly without actually doing the submits...

Question by:jasonsbytes
    LVL 48

    Expert Comment

    I'm not really sure what you're trying to do.

    1. What format are the actions in QA recorded?

    2. When you say you what to simulate a form submit without actually doing the submit, do you mean you don't want the Perl/CGI script to actually do any thing with the parameters?
    LVL 17

    Author Comment

    over in QA a user submits a form that posts data to a database...  There are many different forms and they may edit data, delete data, add new data using different forms.  This is all handled normally, form posts, cgi reads param('formkey'), does something with it, updates Oracle.

    While all of that is happening, I'm recording arbitrary actions in a db.  Like 'added new blah record' with key 'blah' to table 'blah'.

    There may be many of these actions for one 'session' or 'view' whatever you want to call it.

    Then in prod, I want to loop through these actions, pull the data from the qa db associated with each action, call the same script with the same parameters and set the param('blah') values so the script does the same thing in prod as what the person did in qa.  

    It will loop through many of these, setting and resetting param('keys') to match the actions...  I'm just trying to reuse code...  

    Does that help?
    LVL 17

    Author Comment

    If I assign a value to param('town'), does that work?

    can i say:
    param('town') = 'Huston';
    without submitting a form with a textbox named 'town'?
    LVL 39

    Assisted Solution

    If your forms use the GET method, you can use your log file in the QA environment to make the same requests in your prod environment.
    If your forms use the POST method, the QA forms will have to save the post data somewhere, then the prod forms will have to get data from there.

    If you are using the CGI module, it has options that allow it to get it's data from a file, instead of from the actual GET and POST data.  See here:
    LVL 48

    Assisted Solution

    Why not just specify the parameters from the command line, eg:

    /path/to/cgi-bin/script.cgi param1=value1 param2=value2

    LVL 51

    Accepted Solution

    > If I assign a value to param('town'), does that work?

    But I don's see how this should help if you set the parameters in the script itself you don't need to use CGI either ...

    > Then in prod, I want to loop through these actions,
    do mean something like

    wget http://your.tld/path/to/script?par1=val1&par2=val2

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
    I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    761 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

    14 Experts available now in Live!

    Get 1:1 Help Now