The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> save form data locally, saving html form data into text file
kjpr
post Sep 3 2013, 12:35 PM
Post #1





Group: Members
Posts: 7
Joined: 27-August 13
Member No.: 19,628



Hello all,

I am trying to save the input form data locally in a text file. I dont have access to the webserver. so, i am planning to save the data locally at first and then change the path , once i get the access.
the issue i have here is that i am not able to open a text file and write the inputs into it..i am pasting my code.Please take a look at it and let me know where i am going wrong..
CODE

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>

</style>
<script type="text/javascript">
  $(function(){
  
     $('form').submit(function(event){
   event.preventDefault();
   window.location = $('input[type=radio]:checked').val();
   });
   });
</script>
<script>
//  put the data into a file in the current directory called "data.txt"

if (isset($_POST['submit'])) {

// Put the contents of the forms into the file
   file_put_contents('./data.txt', $_POST['url'], FILE_APPEND);
   file_put_contents('./data.txt', $_POST['Dataset'], FILE_APPEND);
   file_put_contents('./data.txt', $_POST['checkbox1'], FILE_APPEND);
   file_put_contents('./data.txt', $_POST['checkbox2'], FILE_APPEND);
   file_put_contents('./data.txt', $_POST['checkbox3'], FILE_APPEND);
   file_put_contents('./data.txt', $_POST['checkbox4'], FILE_APPEND);
   file_put_contents('./data.txt', $_POST['checkbox5'], FILE_APPEND);
  

}
</script>


</head>


<body>
<div id="stylized" class="myform">
<form name="form" method="post" action="">

<label> New Data set: </label>

    <input type="radio" name="url" value="Inputs1.html"/> Yes
    <input type="radio" name="url" value="ResultsPage.html"/> No
    
<br><br>
<label>Dataset description:
</label>
<input type ="text" name= "Dataset" size="30"><br><br><br>
<table id="Previous Datasets">
  <tr>
    <th>Check</th>
    <th>Token Number</th>
    <th>Dataset description</th>
  </tr>
  <tr>
    <td><input type="checkbox" name="checkbox1"></td>
    <td>234567</td>
    <td>MHEX North America Dataset</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="checkbox2"></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td><input type="checkbox" name="checkbox3"></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td><input type="checkbox" name="checkbox4"></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td><input type="checkbox" name="checkbox5"></td>
    <td></td>
    <td></td>
</tr>
</table>
<div style="text-align: center"><br>
  <input type="Submit" name="submit" value="Submit" class="submit">
<div class="spacer"></div>
</form>
</div>
</body>


Thanks in advance
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 3 2013, 01:14 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



The only thing you can create on a user machine from the Web is cookies.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
kjpr
post Sep 3 2013, 01:17 PM
Post #3





Group: Members
Posts: 7
Joined: 27-August 13
Member No.: 19,628



I dont know how to do that.. Could you please modify my code ..

Thanks




QUOTE(pandy @ Sep 3 2013, 01:14 PM) *

The only thing you can create on a user machine from the Web is cookies.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
kjpr
post Sep 3 2013, 02:38 PM
Post #4





Group: Members
Posts: 7
Joined: 27-August 13
Member No.: 19,628



Hello all,
I have updated my script to read the checkbox options in the table.
But, i still have no clue about writing the data to txt file locally..please find the code below and let me know the modifications to make it work.. Thanks in advance


CODE

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>

<script type="text/javascript">
if (isset($_POST['submit'])) {

// Put the contents of the forms into the file
//file_put_contents('./data.txt', $_POST['url'], FILE_APPEND);
   file_put_contents('./data.txt', $_POST['Dataset'], FILE_APPEND);
   file_put_contents('./data.txt', $_POST['condition'][index], FILE_APPEND);
   $("#form > table > tr").each(function(){
     var checkbox = $(this).find("input [type=checkbox]");
     var Token Number = $(this).find("td:eq(1)").text();
     $(this).find("checkbox").val(Token Number);
});
  $(function(){
  
     $('form').submit(function(event){
   event.preventDefault();
   window.location = $('input[type=radio]:checked').val();
   });
   });
</script>


</head>


<body>
<form name="form" method="post" action="">

<label> New Data set: </label>

    <input type="radio" name="url" value="Inputs1.html" checked/> Yes
    <input type="radio" name="url" value="ResultsPage.html"/> No
    
<br><br>
<label>Dataset description:
</label>
<input type ="text" name= "Dataset" size="30"><br><br><br>
<table id="Previous Datasets">
  <tr>
    <th>Check</th>
    <th>Token Number</th>
    <th>Dataset description</th>
  </tr>
  <tr>
    <td><input type="checkbox" name="condition[]"></td>
    <td>234567</td>
    <td>MHEX North America Dataset</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="condition[]" value="Token"></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td><input type="checkbox" name="condition[]"></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td><input type="checkbox" name="condition[]"></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td><input type="checkbox" name="condition[]"></td>
    <td></td>
    <td></td>
</tr>
</table>
<div style="text-align: center"><br>
  <input type="Submit" name="submit" value="Submit" class="submit">
<div class="spacer"></div>
</form>
</div>
</body>







QUOTE(kjpr @ Sep 3 2013, 01:17 PM) *

I dont know how to do that.. Could you please modify my code ..

Thanks




QUOTE(pandy @ Sep 3 2013, 01:14 PM) *

The only thing you can create on a user machine from the Web is cookies.



This post has been edited by kjpr: Sep 3 2013, 02:42 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 3 2013, 02:58 PM
Post #5


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(kjpr @ Sep 3 2013, 07:35 PM) *

I am trying to save the input form data locally in a text file. I dont have access to the webserver. so, i am planning to save the data locally at first and then change the path , once i get the access.

In that case javascript and cookies seems like a bad idea, unless you plan to rely on cookies for the published site as well. Instead you might download a test server to use locally, in which case e.g. PHP run on it can write to local text files. The Apache server, PHP module and (optionally) MySQL database are free to download, but I've heard that complete packages like XAMPP are easier to install/configure.

BTW your code examples seem to mix PHP and javascript inside SCRIPT elements. PHP is only parsed on the server, while javascript is parsed in the user's browser. See also http://www.php.net/manual/en/language.basi...tax.phptags.php
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 3 2013, 03:06 PM
Post #6


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



I didn't mean you should use cookies (even if it may be a possibility). I meant that you can't do what you want. You can't create and/or change files on a user machine, even if it happens to be your own. Well, apart from cookies, that is. wink.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 3 2013, 06:29 PM
Post #7


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Sep 3 2013, 10:06 PM) *

You can't create and/or change files on a user machine, even if it happens to be your own.

Not with javascript, but with server-side scripting (run by a server program on a user machine) you can.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 4 2013, 01:09 AM
Post #8


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



The problem is he isn't using something server side. Still, while you can download a file, it would be hard to edit a file without going through the whole upload and save processes.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 4 2013, 07:04 AM
Post #9


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Sep 4 2013, 08:09 AM) *

The problem is he isn't using something server side.

My reading is that he will do so later:
"I dont have access to the webserver. so, i am planning to save the data locally at first and then change the path , once i get the access."

but until he gets a proper web host he wants to work locally, in which case a local test server is the way to go IMO.

Not sure what we are discussing here... huh.gif







User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 4 2013, 08:12 AM
Post #10


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Sure, but then the file will be on the server, not the local machine. Even if it happens to be the same computer.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 23rd April 2024 - 04:10 AM