how to save html form details into a textfile by hitting the submit key.help me...

by jer000
5 replies
how to save html form details into a textfile by hitting the submit key.help me...
#details #form #hitting #html #keyhelp #save #submit #textfile
  • Profile picture of the author jeffmoser
    Well...here's the quick answer, assuming use of php, and that you know a little about this:

    1. On the form target page, gather the submitted form data into a single string variable, formatted as you'd like to see it.
    2. use fopen() to open a writeable file
    3. use fwrite() to write the string to the opened file.
    4. use fclose()...just to keep things tidy.

    If you need more detail...I've been intending to write some basic php articles on my site. This might as well be the first one. Let me know if you'd like to see it.
    {{ DiscussionBoard.errors[6917160].message }}
    • Profile picture of the author jer000
      can you give php codes..please friend....
      {{ DiscussionBoard.errors[6917194].message }}
  • Profile picture of the author Big Squid
    Here's the code you need...

    It assumes that the "name" of the submit button is "submit". If this is not the case, you need to change either the name of the submit button or the name of the $_POST['submit'] to match up.

    The only other thing you need to do is to name the $filename what you want the filename to be. If you want the file placed in a directory, say submissions/filename.txt, then you need to include that in your filename ($filename = 'submissions/filename.txt'

    If you need help, let me know...

    <?php
    if(isset($_POST['submit'])) {
    $filename = 'filename.txt';
    $fp = @fopen($filename, 'w');
    foreach($_POST AS $key=>$data) {
    @fwrite($fp, $data."\r\n");
    }
    @fclose($fp);
    }
    ?>
    {{ DiscussionBoard.errors[6917465].message }}
    • Profile picture of the author eswariseo
      @Big squid Thanks for the good code information.
      For more details just refer the following link
      Tizag.com/phpT/filewrite.php
      {{ DiscussionBoard.errors[6940143].message }}
      • Profile picture of the author mmrumii
        Originally Posted by eswariseo View Post

        @Big squid Thanks for the good code information.
        For more details just refer the following link
        Tizag.com/phpT/filewrite.php
        I have checked your link it's really useful.
        You buddy rocking. Thanks a lot for your kinda help.
        {{ DiscussionBoard.errors[6940180].message }}

Trending Topics