Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    HTML Form submit/ write to a txt file or email

    Hi all I am totally new with programming as you will see with my question. I am trying to build a basic form where users can click a checkbox to a reference and leave a comment and the output would either be sent to myself by email or evrything stored into a txt file. The HTML form I think I can produce its the actual returning result(writing to txt file) I can't figure out. This is all I have at the moment. Any help would be great. thanks

    <form name="input" action="Comments.txt" method="get">
    Reference<input type="checkbox" name="ref" value="Reference">
    Comment: <input type="text" name="Comments">
    <input type="submit" value="Submit">
    </form>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,175
    Thanks
    23
    Thanked 601 Times in 600 Posts
    n3w2js - writing a form to a text file or to email requires a server side program to do the deed as does just processing the form. The form action is change to go to a PHP file and name is changed (Not an attribute) to ID(which is).
    The form:
    Code:
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta charset="UTF-8" />
    <title>Title of the document</title>
    </head>
    <body>
    
    <form id="input" action="test.php" method="get">
    Reference<input type="checkbox" name="ref" value="Reference">
    Comment: <input type="text" name="Comments">
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>
    The PHP file test.php:
    PHP Code:
    <?php
    $ref 
    $Comments '';
    if(isset(
    $_GET["ref"])) $ref $_GET["ref"];
    if(isset(
    $_GET["Comments"])) $Comments $_GET["Comments"];

    if (
    $ref <> ''){
        
    $fp  fopen('commentfile.txt''a+');
        
    fwrite($fp$Comments."\n");
        
    fclose($fp);
    }
    ?>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    n3w2js (04-23-2014)

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    it's also just as easy to use the mail function, depends which method you would rather have, sent or stored?

  • #4
    New Coder
    Join Date
    Apr 2014
    Location
    Liverpool
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's probably better, and easier, to simply use the send method to have the form entries emailed to you.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •