Welcome visitor
* Login
* Register
It is currently September 15th, 2019, 11:57 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » HTML



Post new topic Reply to topic  [ 2 posts ] 
Author Message
  Send a form to be saved on my local disk
PostPosted: November 12th, 2009, 7:13 am 

Posts: 16
Hi, I just started learning about HTML and forms. When the form is submitted it is sent to the "action" file, right? Do you know how to send the data to the local disk? my hard drive?

thank you ppl.


Top
 Profile  
 
  Re: Send a form to be saved on my local disk
PostPosted: November 12th, 2009, 7:51 pm 
User avatar

Posts: 112
Well, in first place you need a server-side script to handle your form data, lets say PHP.
http://www.scriptingok.com/tutorials-category/PHP-MySQL

Then, you need to have in mind that your form will be received on tha same computer that hosts your site. If you are using a remote server, the form will be "read" on the remote server and, in order to get to your local disk you will need to download it.

Now, to summarize, use this PHP script that will create a file called "data.txt" on your server which you can later copy-paste to your local drive:
<?php
extract($_POST);
$filename = 'data.txt'; //you can rename this variable
$content = 'Name: ' . $name . '
Last name: ' . $last . '
Comments: ' . $comments . '


';
$handle = fopen($filename, 'a');
fwrite($handle, $content);
fclose($handle);
<?php
extract($_POST);
$filename = 'data.txt';
$content = 'Name: ' . $name . '
Last name: ' . $last . '
Comments: ' . $comments . '


';
$handle = fopen($filename, 'a');
fwrite($handle, $content);
fclose($handle);
echo '<a href="form_stored_on_a_file.htm">back</a>';
?>
?>

This PHP is for an HTML like the next one. The HTML file is called form_stored_on_a_file.htm and the PHP form_stored_on_a_file.php, both should be on your server and you only need to go to the HTML file.
<body>
<form name="form" method="post" action="form_stored_on_a_file.php">
<label for="name">Name: </label><input name="name" id="name" />
<br /><br />
<label for="last">Last name: </label><input name="last" id="last" />
<br /><br />
<label for="comments">Comments: </label>
<br />
<textarea name="comments" cols="40" rows="5"></textarea>
<br /><br />
<input type="submit" value="Send Data" />
<input type="reset" value="Clear"/>
</form>
</body>
</html>


see also http://www.scriptingok.com/forum/t5_964-Create-a-file-from-a-textarea


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

FORUMS » Client Side » HTML


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron