Forum Moderators: coopster
<html>
Form Input-
Full_Name:
Organization:
Special_Instructions:
</html>
<php>
Creates new text file with filename: "Organization".txt
Adds form info into text file.
</php>
Any help is appreciated!
I had a few minutes off and took a closer look into your problem.
I've put together a little code which I believe will be exactly what you need. You can change it further according to your needs. You'll see I also added a date entry for your inputs, but you can just delete it if you don't need it:)
If you have any questions regarding the code, feel free to ask !
Enjoy!
FORM TO .TXT SCRIPT:
<style type="text/css">
<!--
.inputtitle {
float:left;
width: 86px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #333;
padding-bottom: 12px;
}
.divider{
clear:left;
}
.warn{
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #900;
padding: 4px;
border: 1px solid #CCC;
float: left;
margin-bottom: 12px;
}
.success{
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #063;
padding: 4px;
border: 1px solid #CCC;
float: left;
margin-bottom: 12px;
}
-->
</style>
<?php
function nicename($str){
$str = str_replace(" ","_",$str);
$str = strtolower($str);
$str = trim($str,"_");
return $str;
}
if(isset($_POST['send'])){
if($_POST['full_name']=="" ¦¦ $_POST['organization']==""){
echo '<div class="warn">Please enter the required information..</div><div class="divider"></div>';
}
else{
$organization = nicename($_POST['organization']);
$new_textfile = $organization.".txt";
$nfile = fopen($new_textfile, 'w');
$data = "full name: ".$_POST['full_name']."\r\n";
fwrite($nfile, $data);
$data = "organization: ".$_POST['organization']."\r\n";
fwrite($nfile, $data);
if($_POST['special_instructions']==""){
$special_instructions = "N/A";
}else{
$special_instructions = $_POST['special_instructions'];
}
$data = "Special instructions: ".$special_instructions."\r\r\n\n";
fwrite($nfile, $data);
$data = "entry time: ".date("Y-m-d H:i:s")."\r\n";
fwrite($nfile, $data);
fclose($nfile);
echo '<div class="success">Your information was succesfully added !</div><div class="divider"></div>';
}
}
?>
<form action="" method="post" name="details" target="_self">
<div class="inputtitle">Full name:</div>
<input name="full_name" type="text">
<div class="divider"></div>
<div class="inputtitle">Organization:</div>
<input name="organization" type="text">
<div class="divider"></div>
<div class="inputtitle">Special instructions:</div>
<textarea name="special_instructions" cols="34" rows="6"></textarea>
<div class="divider"></div>
<div class="inputtitle"></div>
<input name="send" type="submit" value="send">
</form>
Note: it creates a .txt file in the folder where you place this script, if you want it to save to a different folder, for example your subfolder then you would have to change this line:
$new_textfile = $organization.".txt";
$new_textfile = "myfolder/".$organization.".txt";