Current location: Hot Scripts Forums » General Community » Script Requests » write a form to a text file

write a form to a text file

Reply
  #1 (permalink)  
Old 02-22-07, 05:22 AM
eviljoker7075 eviljoker7075 is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation write a form to a text file

Hey guys I desperately need some help. I'm supposed to have completed a petition but forgot about it, so thought I'd set up one online really quickly.

I just need some help, I'm not sure how to submit the fields o a form to a simple text file. Please can someone yhelp me with this, thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-28-07, 04:42 PM
muddy9494 muddy9494 is offline
New Member
 
Join Date: Feb 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by eviljoker7075 View Post
Hey guys I desperately need some help. I'm supposed to have completed a petition but forgot about it, so thought I'd set up one online really quickly.

I just need some help, I'm not sure how to submit the fields o a form to a simple text file. Please can someone yhelp me with this, thank you
i need the same thing
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-28-07, 05:36 PM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Well,

First you will need a CGI (Perl/php) to parse form data. Google will be your friend.
Next output form data to a file:

Perl Based code.
open(OUT,">formdata.txt");
print OUT "FNAME $FORMDATA[0]\tLNAME $FORMDATA[1]\tEMAIL $FORMDATA[2]\n";
print "Thanks for submitting our form.<p>";
close OUT;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-28-07, 06:01 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,898
Thanks: 0
Thanked 63 Times in 61 Posts
PHP Code:
// PHP Based code.
$open_file fopen("formdata.txt""w");  // Open file for writing. //
fwrite($open_file$fname."\n");
fwrite($open_file$lname."\n");
fwrite($open_file$email."\n");
echo( 
"Thanks for submitting our form.<p>");
fclose($open_file); 
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-28-07, 06:21 PM
Nico's Avatar
Nico Nico is online now
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,648
Thanks: 6
Thanked 33 Times in 30 Posts
Note that the previously submitted data gets erased when writing to the log file which has been opened in "w" mode. Replace the "w" with "a", to add the new data below the old data.

http://www.php.net/fopen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 02-28-07, 07:13 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,898
Thanks: 0
Thanked 63 Times in 61 Posts
When I used to use flat files, I couldn't get the append mode to work properly. So
I always read my file into an array then added my new data to the array and then wrote the array back to the file using the write mode.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 03-02-07, 04:15 AM
topside topside is offline
New Member
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question

Jerry,

Not sure where to place that PHP code. Does that code go in its own file? If so, do you set the file name as a form action ?

Yes I'm VERY new to PHP, sorry to be so totally clueless. Thanks for your help.

JR
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 03-02-07, 06:42 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,898
Thanks: 0
Thanked 63 Times in 61 Posts
If you want to program even the basic functions that you will need on the internet today,
it becomes necessary to learn HTML, CSS, javascript & PHP.

HTML is used to organize and display your data.

CSS is used to format & organize your data.

Javascript is used to manipulate the objects and elements on the screen(it can also do anything that HTML and CSS can do),

and PHP is used for communicating with files & databases, manipulating arrays, sending email and a whole lot more.

So if you already have a basic understanding of HTML, than you are half way there to learning PHP.
PHP is used in the same document that your HTML is in.
You just need to learn how to talk to files with PHP.
The code I presented is the basic structure for creating and writing to a file.

The only other concideration for now is: HTML files usually have a file extention of .html or .htm, but when you add in PHP then you change the extention to .php that way the script interpreters know that you are programming in PHP.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 03-03-07, 08:19 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,898
Thanks: 0
Thanked 63 Times in 61 Posts
Oh, yes, I neglected to mention one thing... Make sure you enclose your PHP code in PHP tags, like this:
PHP Code:
<?php
echo("Hello"); 
?>
Some people like to take short-cuts with the PHP tags and use them this way:
PHP Code:
<?  
echo("Hello");   
?>
I don't take that short-cut, because it doesn't always work the way you think it should.
__________________
Jerry Broughton

Last edited by job0107; 03-03-07 at 08:22 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP write to text file veeco Script Requests 2 02-10-10 02:48 PM
Draggable Tables Ares JavaScript 10 08-03-06 06:55 AM
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 03:27 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


All times are GMT -5. The time now is 09:11 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.