Current location: Hot Scripts Forums » Programming Languages » PHP » Form to File?


Form to File?

Reply
  #1 (permalink)  
Old 12-30-03, 10:44 AM
kazz kazz is offline
New Member
 
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Form to File?

I am not sure how to work with PHP. I am learning...First time using PHP. I am working on a survey form do today. I am using a script that I copied from some site. What it does it writes the inf of a form into a txt file. It works fine . But. some of the questions on the survey have more that one answer (you can check one or more check boxes). For the question w/checkboxes.The script will write int the txt the last selection checked. I need to be able to write all selected options to the txt file and the one that are not check show as empty on the txt file. I will use the content of the txt file to create graphics. I don't like just to copy script but I need to finish this 30 question survey by today.

This is a sample of what i have:

<html>
<head>
<title> </title>
</head>
<body>
<form action="DataCollector.php" method="post" name="survey">
<input type="hidden" name="n" value=0>
<table width="92%" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC" class="bodyBlueText">

<tr>
<td colspan="6"><strong>4.</strong> Organization <br>
<select name="q4" id="select">
<option selected>Select One
<option value="Option1">Option1
<option value="Option2">Option2
<option value="Option3">Option3
<option value="Option4">Option4
<option value="Option5">Option5
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td <p><strong>5</strong>. What is your professional focus <br>
<input type="checkbox" name="q5" value="Health and Wellness">
Health and Wellness<br>
<input type="checkbox" name="q5" value="Diversity">
Diversity/EEO<br>
<input type="checkbox" name="q5" value="Work">
Work/Life<br>
<input type="checkbox" name="q5" value="Employee Assistance Programs">
Employee Assistance Programs<br>
<input type="checkbox" name="q5" value="Employee Relations">
Employee Relations<br>
<input type="checkbox" name="q5" value="Benefits">
Benefits<br>
<input type="checkbox" name="q5" value="Other">
Other<br>
</td>
</tr>
<tr>
<td><strong>6.</strong> Question 6</td>
</tr>
<tr>
<td><select name="q6" id="q6">
<option selected>Select One
<option value="Twice a year (all day sessions)">Twice a year (all day
sessions)
<option value="Twice a year (half day sessions)">Twice a year (half day
sessions)
<option value="Quarterly (half day sessions)">Quarterly (half day sessions)
<option value="Other">Other
</select></td>
</tr>
<tr>
<td><strong>7.</strong> WQuestion 7</td>
</tr>
<tr>
<td><p>
<input name="q7" type="radio" value="Yes">
Yes
<input type="radio" name="q7" value="No">
No<br>
</p>
</td>
</tr>
<tr>
<td><strong>8.</strong> Question 8?</td>
</tr>
<tr>
<td><input type="radio" name="q8" value="Yes">
Yes
<input type="radio" name="q8" value="No">
No<br>
</td>
<td>&nbsp;</td>
</tr>

<tr>
<td><br><strong>14.</strong> Question 14<br>
<input type="checkbox" name="q14" value="Conference information"> Conference information<br>
<input type="checkbox" name="q14" value="Quick Tips for Workplace Effectiveness"> Quick Tips for Workplace Effectiveness<br>
<input type="checkbox" name="q14" value="Calendar"> Calendar<br>
<input type="checkbox" name="q14" value="Resources Page with links to other helpful websites"> Resources Page with links to other helpful websites<br>
<input type="checkbox" name="q14" value="Job opportunities"> Job opportunities</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong>15.</strong> Quetion 15<br>
<textarea name="q15" cols="45"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit Survey"></td>
</tr>

</table>
</form>

</body>
</html>


---------------------php file
<?php
############################
# modify path to text file
############################
$data[0] = "file.txt";

###################################
# OPEN FILE AND WRITES TO A TXT FILE
###################################
if(!$fp = fopen($data[$_REQUEST['n']], "a")) die ("Cannot open data file");

array_shift($_REQUEST);
$size = sizeof($_REQUEST);
for($i=0; $i<$size; $i++) {
$str = $str . array_shift($_REQUEST);
if(!($i==($size-1))) {
$str = $str . ", ";
}
}
fwrite($fp, $str . "\n\r");
echo "<p>Thank You</p><p>The data was successfully saved.</p>";
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 03:06 AM
Write form data to file dragge PHP 1 12-27-03 07:26 PM
Please I Need help before all my hair is gone! LisatheNovice Perl 6 11-22-03 03:05 PM
Need to submit form to database and text file - Any ideas how? dpreiss ASP 1 08-21-03 06:02 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM


All times are GMT -5. The time now is 07:49 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.