LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 11-12-2008, 04:45 PM   #1
OldGaf
Member
 
Registered: Feb 2008
Posts: 47

Rep: Reputation: 15
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-
 
Old 11-12-2008, 05:05 PM   #2
teknik
Member
 
Registered: Jun 2006
Location: Winnipeg, Canada
Distribution: Slackware 12.1
Posts: 33

Rep: Reputation: 16
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";
 
Old 11-12-2008, 07:18 PM   #3
OldGaf
Member
 
Registered: Feb 2008
Posts: 47

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by teknik View Post
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-
 
Old 11-12-2008, 07:53 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: build query from form entry, then display results in the same form tonedeaf1969 Programming 4 06-22-2007 07:55 AM
HTML form to read/write from local file mustangfanatic01 Linux - Software 2 03-11-2006 03:29 PM
read/write in *.MDB (MS-Access file) form Linux FC3 thuan1975 Linux - Software 1 08-11-2005 01:25 AM
shell script works form command line but not form crontab saifee General 1 10-14-2004 10:27 AM
I want Linux source code for FAT file system in user readable form not in binary form ramya272 Linux - Newbie 5 02-05-2004 07:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration