Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
laziness, impatience, and hubris
 
PerlMonks  

Input button question

by dawnamarr (Novice)
on Apr 19, 2001 at 18:17 UTC ( #73823=perlquestion: print w/ replies, xml ) Need Help??
dawnamarr has asked for the wisdom of the Perl Monks concerning the following question:

Hope this doesn't sound really dumb - just don't have a clue as to what I am doing.

Here's a piece of the code. When I click on this button, it takes me to my .pl page. That script needs to be run to update the html page, but is there a way that I can call the script to be run, while also taking me directly to the html page when the button is hit?

print "<TD><FORM METHOD=POST ACTION=$cgiurl>"; print "<INPUT TYPE=HIDDEN NAME=Month VALUE=$NextMonth>"; print "<INPUT TYPE=HIDDEN NAME=Type VALUE=\"$INPUT{'Type'}\">"; print "<INPUT TYPE=SUBMIT VALUE=\"Next Month\">"; print "</FORM></TD>\n";


I have a feeling this may not be enough information to give me a correct anwser but I am trying please help???

Comment on Input button question
Download Code
Re: Input button question
by suaveant (Parson) on Apr 19, 2001 at 18:21 UTC
    Yes, what you do is put in your script...
    print "Status: 302 Moved Temporarily\n" print "Location: name_of_page.html\n\n";
    In place of your headers... and that will do a silent redirect from your script to the page. You may want to wait to print the headers to redirect until your script is done, so you are sure they will get the updated page (if you are sending them to the page you are updateing)

    you can't really do it from the form, though.
                    - Ant

Re: Input button question
by THRAK (Monk) on Apr 19, 2001 at 18:27 UTC
    Chances are if you feel you haven't provided enough info, then you probably haven't! Generally this means you don't understand your own explaination so obviously it will be even tougher for those who are not inside your mind. Just my take on that comment.
    It sounds like you want to run your script and go directly to the HTML page at the same time. (?) You can't have two actions for a single event, but you could call the script and at the end do a redirect to the page. If you don't always want to redirect to that page you will have to determine that by data you pass. (e.g. detect value of some hidden field.) Somewhat of a stab in the dark, maybe this will help you.

    -THRAK
    www.polarlava.com
      Yes, that is exaclty what I want to do, and I do want to do it each time that button is pushed.

      Think you could provide an example? The code in the first reply isn't working for me - it only prints those statements out to the .pl page.
        You would be better off posting what you have and what it is you are trying to accomplish. You can do a redirect using something like:
        print $cgi->redirect($cgiurl);.
        This is functionally equivalent to what suaveant has above.
        You can learn more about the CGI module here.

        -THRAK
        www.polarlava.com

        I'm still not quite clear on the sequence of events, but I'm going to put what I think is happening and then what I think you should do (this is what we call "error propagation" in my line of work...)

        1. Point browser to FOO.html
        2. submit form to BAR.pl
        3. BAR.pl modifies FOO.html
        4. Browser is redirected to FOO.html

        Is that right? If so, then the first suggestion is more or less right (for the "less", see use CGI or die;). The key is that those statements must be the first and only things printed to STDOUT by BAR.pl--if you print out a regular header first (using the header() method from CGI.pm), then it will just become part of the document body.

        Since I've made a fair passel of assumptions so far, I'll go ahead and assume you're using CGI.pm, as well. In which case, replace your call to print header("text/html"); with one to print redirect($new_url); and all will be well.

        I hope some of this is helpful--if my assumptions are totally off, we can go another round. :-)



        If God had meant us to fly, he would *never* have give us the railroads.
            --Michael Flanders

        Probably what is happening is you are printing out other headers above the redirect headers...

        leave out the normal print "Content-Type: text/html\n\n"; or whatever you use and use mine... or if you are using CGI.pm, use the redirection routine that was pointed out below.
                        - Ant

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://73823]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2014-04-24 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls