Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: How do i refresh a page from the perl script.

by thabenksta (Pilgrim)
on Jul 02, 2001 at 22:35 UTC ( [id://93273]=note: print w/replies, xml ) Need Help??


in reply to How do i refresh a page from the perl script.

Assuming that the cgi script is what's creating the form and that you are using CGI, you could do something similar to the following.

#!/usr/local/bin/perl -w use strict; use CGI my $q = CGI::new(); print <<HTML; <form action="name of this script.cgi"> Name: <input type="text" name="Name" value="$q->param{'Name'}"> Address: <input type="text" name="Address" value="$q->param{'Address +'}"> <input type="submit" value="Refresh"> </form> HTML

Basically, if $q->param{'Address'} exists, it will fill that in as the value in the form.

Hope that helps.

-thabenksta
my $name = 'Ben Kittrell'; $name=~s/^(.+)\s(.).+$/\L$1$2/g; my $nick = 'tha' . $name . 'sta';

Replies are listed 'Best First'.
Re: Re: How do i refresh a page from the perl script.
by epoptai (Curate) on Jul 02, 2001 at 23:14 UTC
    With -w enabled you can't use params like that without getting uninitialized value warnings when the params aren't defined. Also $q->param{'Address'} shouldn't have curly braces but parentheses: $q->param('Address').

    This version shows a way to properly initialize the variables whether the params exist or not.

    #!/usr/local/bin/perl -w use strict; use CGI; my $q = CGI::new(); my $name = $q->param('Name') || ''; my $addy = $q->param('Address') || ''; print $q->header; print <<HTML; <form> Name: <input type="text" name="Name" value="$name"> Address: <input type="text" name="Address" value="$addy"> <input type="submit" value="Refresh"> </form> HTML

    --
    Check out my Perlmonks Related Scripts like framechat, reputer, and xNN.

Re: Re: How do i refresh a page from the perl script.
by anjaana78 (Novice) on Jul 02, 2001 at 23:15 UTC
    Hi there thanks for the response. let me be more clear with my problem. I have a pure html page(not cgi). I have 3 buttons on it. first one is the submit and the second one is of type button and the third one is of type button. so the second one is calling the perl script. now this perl script does somethig with parameters i pass. and then gets back to the original page with :
    print "Location:http://mypage.html \n\n";
    but the thing is it doesnot refresh the page so all the fields are gone. Is it possible to just refresh a page from perl and not to restart the whole page again. thanks - anjaana
      The answer to the direct question is "no", and that has more to do with the way HTTP and web browsers work than Perl. In general, a web server doesn't normally send just part of a page to replace an existing page. There are ways to do this with JavaScript and other client-side programs as well as with multipart transfers. That's probably not what you want.

      A simpler explanation is to generate the HTML page within the CGI program. You'll send the whole thing to the browser, but you'll have the opportunity to substitute in your preferred parameters. If you follow this road, you might end up coding the whole thing as a Perl program, integrating the static HTML page into the program or as a template or something. If there are no parameters passed (that is, the user pressed no buttons, just loaded the page for the first time), send a blank form. If the user pressed a button, perform the appropriate action.

      Doing much of anything else makes a lot of assumptions about the web browser. In some cases, you can get away with that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://93273]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-16 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found