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.
Coastal Web
03-06-2005, 02:48 AM
Yes you'd need PHP at the very least to pull something like that off:
here's an example:
<?php
//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
if(isSet($_POST['submit'])){
//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);
fclose($fd);
//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!
end;
//we'll exit here, since we're done.
exit;
} 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">
<br>
Last Name: <input type="text" value="" name="Lname">
<br>
E-mail Address: <input type="text" value="" name="email_address">
<input type="submit" value="submit" name="submit">
<input type="reset" value="reset" name="reset">
</form>
end;
//script is done, lets exit
exit;
}
?>
That's the basics... l'm sure someone around here will be able to elaborate on it a bit for you.
Samantha G.