LinuxQuestions.org
Review your favorite Linux distribution.
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 05-17-2012, 01:26 PM   #1
imran042
Member
 
Registered: Feb 2012
Posts: 35

Rep: Reputation: Disabled
saving the form data into a .txt file


how to save(perl /html /cgi script) upload details into a textfile by hitting the submit key.

below is my script:
how to save the form data into a txt file by pressing the submit key.



#!/usr/bin/perl -w
print "content-type:text/html\n\n";

print <<END_HTML;
<form action="/cgi-bin/reply.pl" method="get">
<html>
<head>
<title>Form</title>
</head>
<body>

<fieldset>
<legend><h3>Personel details</h3></legend>
<br>
First name: <input type="text" name="firstname">
<br>
<br>
Last name: <input type="text" name="lastname">
<br>
<br>
Email Address:<input type="text">
<br>
<br>
Age Betweeen: <select>
<option>1-5</option>
<option>6-10</option>
<option>11-15</option>
<option>16-20</option>
<option>21-25</option>
<option>26-30</option>
<option>31-35</option>
<option>36-40</option>
<option>40-45</option>
<option>46-50</option>
</select>
<br>
<br>
Gender:<input type="radio" name="sex" value="male"> Male
<input type="radio" name="sex" value="female"> Female
<br>
<br>

City: <input type="text" name="city">
<br>
<br>
State: <input type="text" name="state">
<br>
<br>
Country:<input type="text" name="country">
<br>
<br>
<input type="submit" value="Submit">

</fieldset>
</body>

END_HTML
 
Old 05-17-2012, 02:31 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,590

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Code:
open (MYFILE, '>>data.txt'); 
print MYFILE "data to write"; 
close (MYFILE);
Replace the data with your form variables on your reply.pl script that it gets posted to.
 
Old 05-18-2012, 08:53 AM   #3
imran042
Member
 
Registered: Feb 2012
Posts: 35

Original Poster
Rep: Reputation: Disabled
whatever details are entered in the script form, should be automatically save in as a text file,
not by manually saving.

it should automatically save the form data into a text file, as soon as pressing the submit button.
 
Old 05-18-2012, 02:48 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,590

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
That is the code I gave you.. When they click submit it posts the data to your reply.pl script. Add lines similar to the code above to write those variables to a file.
 
Old 05-18-2012, 02:53 PM   #5
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,590

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Here is a more indepth example I found on www.howtodothings.com:

Code:
<FORM ACTION="../cgi-bin/script.pl" METHOD="POST">
<INPUT TYPE="TEXT" NAME="fname">
<INPUT TYPE="TEXT" NAME="lname">
...
</FORM>

&populatePostFields;  #Perl grabs all the post data into a hash
$firstName = $postFields{ "fname" }; #You pull what data you want and set it to a variable
$lastName = $postFields{ "lname" }; # same as previous line for a different form field

open (MYFILE, '>>data.txt');  #opens file data.txt to write to
print MYFILE "$firstName";  #Writes the variable $firstName
print MYFILE "$lastName";  #Writes the variable $lastName
close (MYFILE); #closes the file
 
  


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
extract last few of line data from txt file irwinyeo Programming 7 12-20-2011 10:47 AM
C - how to open a txt file and then display the data UltimateDesi Programming 20 10-17-2010 11:32 AM
Script for pulling data out of a txt file schapman43 Linux - Newbie 7 08-03-2010 02:07 PM
Saving shutdown text screen into a txt file. glore2002 Debian 2 03-30-2010 04:29 AM
Using nslookup from data in a .txt file in BackTrack RexRogan Linux - Newbie 1 12-08-2009 03:35 AM


All times are GMT -5. The time now is 01:11 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration