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

    storing form fields

    I want to make a form with only a few fields (five, at the most) that will store the input into a text file, or better yet, an HTML document.

    Can you do this in HTML? Or even Javascript? Or is a stronger language like PHP needed?

    For coding purposes, I will have fields named First Name, Last Name, & Credits. I may expand later, but that's good for now.

  • #2
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Thanked 3 Times in 3 Posts
    Yes you'd need PHP at the very least to pull something like that off:
    here's an example:

    //note: edit the full path to the .html file that you'd like to have edited
    //and chmod it to 777
    //name this file: form.php

    //check if the form was submitted

    //form was submitted

    //here we'd better clean up the user input before we print it to your site
    $first_name = trim(stripslashes(strip_tags($_POST['Fname'])));
    $last_name = trim(stripslashes(strip_tags($_POST['Lname'])));
    $email_address = trim(stripslashes(strip_tags($_POST['email_address'])));

    //done cleaning up text lets print it to the .html file

    $fd = fopen("/home/path/to/file.html", "a+"); //<-edit with path to file
    $fstring = fread($fd, filesize("/home/path/to/file.html")); //<-edit with path to file

    //what are we writing to the .html file
    $new_input = "first name: $first_name<br>last name: $last_name<br>email address: $email_address<BR><BR>";

    $fout = fwrite($fd, $new_input);


    //put any HTML that you want to be outputted to the page
    //after "print <<<end" and before "end;"

    print <<<end

    Thank you $Fname, the form has been submitted!


    //we'll exit here, since we're done.
    } else {
    //the form was not submitted so lets show the form

    //put any HTML that you want to be outputted to the page
    //after "print <<<end" and before "end;"
    echo <<<end

    <form method="POST" action="$PHP_THIS">

    First Name: <input type="text" value="" name="Fname">
    Last Name: <input type="text" value="" name="Lname">
    E-mail Address: <input type="text" value="" name="email_address">

    <input type="submit" value="submit" name="submit">
    <input type="reset" value="reset" name="reset">

    //script is done, lets exit

    That's the basics... l'm sure someone around here will be able to elaborate on it a bit for you.

    Samantha G.
    Last edited by Coastal Web; 03-06-2005 at 03:54 AM.


    Posting Permissions

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