Jump to content

Printing out info from a form


hotrod57

Recommended Posts

I have this php function that reads a text file for input to create a form. I am trying to get the form to print out the data on a separate page, but all I get is a blank page. Am I calling the page correctly, or is this even possible to do?

 

<form action="phpform.php" method=POST>
<?php
$field=array(); 
$type=array();
$lines = file('test_read.txt');
foreach ($lines as $line) {
    list($mytype, $name, $option) = explode("=", $line);
    $name = htmlentities(trim($name)); 
    if(isset($option)) 
         $field[$name][]=htmlentities(trim($option)); 
    else 
         $field[$name]='nooptions'; 
    $type[$name]=trim($mytype); 
} 

foreach ($field as $name => $options) { 

    switch($type[$name]) { 

        case 'label': 
            print ("<p>$name<br>\n"); 
            break; 

        case 'checkbox': 
            print ("<input type=\"checkbox\" name=\"$name\" id=\"$name\" value=\"true\"><label for=\"$name\">$name</label>\n"); 
            break; 

        case 'radio_button': 
            print ("<p>$name<br>\n"); 
            foreach($options as $value) 
                 print ("<input type=\"radio\" name=\"$name\" id=\"$name-$value\" value=\"$value\"><label for=\"$name-$value\">$value</label>\n"); 
            break; 
            
        case 'comment_box': 
            print ("<p><label for=\"$name\">$name</label><br>\n"); 
            print ("<p><textarea id=\"$name\" name=\"$name\" rows=\"4\" cols=\"50\"></textarea>\n"); 
           break; 
        	
         case 'textbox': 
           print ("<p><label for=\"$name\">$name: </label><input type=\"text\" id=\"$name\" name=\"$name\">\n"); 
           break; 
           
        case 'dropbox': 
           print ("<p><label for=\"$name\">$name: </label><select name=\"$name\"  id=\"$name\"><option></option>\n"); 
           foreach($options as $value) 
                print ("<option value=\"$value\">$value</option>\n"); 
           print ("</select>"); 
           break; 
          } 
} 
print ("<p><input type=submit name=submit value=\"SUBMIT\"></form>\n");
print ("<input type=reset value=\"Reset\">\n");
?>
</form>

 

 

Text File (just in case):

title = Test Form
label = Choose One of These
checkbox = shoe
checkbox = hair
radio_button = Choose One = 3
radio_button = Choose One = 6
comment_box = Comments
dropbox = Select = 18-29 
dropbox = Select = 30-49 
dropbox = Select = 50-75
textbox = Please type your name

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.