I have this code that is supposed to read a text file and print out a form according to the data in the file. I am using a switch statement to break up the array and separate the values. what I have found out is that if I have more than one item (e.g. checkbox), the switch doesn’t treat them as being in the same category. For example, if I put a statement like ‘Choose one of these:’, and I have three checkboxes, I get three ‘Choose one of these:’ statements on separate lines with checkboxes. Is there any way I could get that statement printed out only once, but still get my three checkboxes, just like on a regular form? And I am having problems with my dropbox as well. Instead of getting the three values in one dropbox, I get three separate dropboxes with one value in each. If anyone could help, I would appreciate it.
Text File:
title = Test Form
checkbox = shoe
checkbox = hair
radio_button = 3
radio_button = 6
comment_box
dropbox = 18-29
dropbox = 30-49
dropbox = 50-75
textbox = 50
PHP Code:
[code]<?php
$lines = file(‘test_read.txt’);
//print (“n”)
foreach ($lines as $line) {
list($field, $value) = explode("=", $line);
$value = substr(trim($value), 0, 100);
switch(trim($field)) {
case 'checkbox':
//print ("<p>Choose one:<br>n");
print ("<input type="checkbox" name="userbox" value="$value">$valuen");
break;
case 'radio_button':
//print ("<p>Choose one:<br>n");
print ("<input type="radio" name="userbox" value="$value">$valuen");
break;
case 'comment_box':
print ("<p><textarea name="commentbox" rows="4" cols="50"></textarea>n");
break;
case 'textbox':
print ("<p><input type="text" name="textbox" size=$value>n");
break;
case 'dropbox':
print ("<p><select name=dropbox><option>Choose One</option>n");
while ($value) {
print ("<option value="$value">$value</option>n");
// for ($n = 0; $n < count($value); $n++) {
// while ($n = 1) {
// $value = $select;
// print ("");
break;
}
}
}
print (“
n”);
?>[/code]