Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-12-2008, 04:45 PM
|
#1
|
Member
Registered: Feb 2008
Posts: 47
Rep:
|
How to write to a file from a form with perl, and not leave the form page.
Hi all,
I would like to have a simple form (one text box) that will post to a perl script which in turn will append the post to a file on the server.
I am new to perl, but know how to write a script to update a file. I also can write a basic form. (impressive eh?)
The catch is that I do not want to leave the form page..... just submit the data and have the text box clear and wait for more input.
Is this possible?
If not, can I have the "confirmation page" redirect me back to the form?
Thank,
-OG-
|
|
|
11-12-2008, 05:05 PM
|
#2
|
Member
Registered: Jun 2006
Location: Winnipeg, Canada
Distribution: Slackware 12.1
Posts: 33
Rep:
|
To do it without leaving the page will require the use of AJAX (Asynchronous Javascript and XML) - don't worry, its easier than it sounds. Do some tutorials on that and you'll find your answer. Basically the solution would require using javascript to send off a request "behind-the-scenes" to your perl script which writes to the file, and then the javascript call would return when the perl script has executed, and at that point you'd clear your text field (again, with javascript). It's easier than it sounds, for sure.
The other way you asked about, where the confirmation redirects back to the form, is also really easy. All you'd have to do in that case is put a header on the confirmation page to redirect back to the form page. You can do this with the following script:
Code:
#!/usr/bin/perl
# this will have to be your first line of output...
print "Location: http://www.your-website.com/yourpage.html\n\n";
|
|
|
11-12-2008, 07:18 PM
|
#3
|
Member
Registered: Feb 2008
Posts: 47
Original Poster
Rep:
|
Quote:
Originally Posted by teknik
To do it without leaving the page will require the use of AJAX (Asynchronous Javascript and XML) - don't worry, its easier than it sounds. Do some tutorials on that and you'll find your answer. Basically the solution would require using javascript to send off a request "behind-the-scenes" to your perl script which writes to the file, and then the javascript call would return when the perl script has executed, and at that point you'd clear your text field (again, with javascript). It's easier than it sounds, for sure.
The other way you asked about, where the confirmation redirects back to the form, is also really easy. All you'd have to do in that case is put a header on the confirmation page to redirect back to the form page. You can do this with the following script:
Code:
#!/usr/bin/perl
# this will have to be your first line of output...
print "Location: http://www.your-website.com/yourpage.html\n\n";
|
Thanks a bunch boss!
I will look at this tomorrow.
-OG-
|
|
|
11-12-2008, 07:53 PM
|
#4
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
Not quite as spiffy, but a lot easier for newbies to implement, would be to have your per CGI simply re-issue the original form. If it is as simple as you say it is, it should re-draw in no time on the browser, and not be too annoying to the user. When using perl for CGI work, I recommend the CGI module available from CPAN. Makes parsing the form data quite painless.
--- rod.
|
|
|
All times are GMT -5. The time now is 09:19 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|