473,813 Members | 3,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing out info from a form

7 New Member
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?

[PHP]<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(tr im($name));
if(isset($optio n))
$field[$name][]=htmlentities(t rim($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($option s 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><textar ea 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\"><o ption></option>\n");
foreach($option s 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>[/PHP]


Text File (just in case):
Expand|Select|Wrap|Line Numbers
  1. title = Test Form
  2. label = Choose One of These
  3. checkbox = shoe
  4. checkbox = hair
  5. radio_button = Choose One = 3
  6. radio_button = Choose One = 6
  7. comment_box = Comments
  8. dropbox = Select = 18-29 
  9. dropbox = Select = 30-49 
  10. dropbox = Select = 50-75
  11. textbox = Please type your name
Nov 6 '07 #1
5 2017
ak1dnar
1,584 Recognized Expert Top Contributor
Your form is working fine, right? So now you need to POST the user inputs to the "phpform.ph p" and print them. Could you please tell us which part is not working, or what is this blank page?
Nov 6 '07 #2
hotrod57
7 New Member
Sorry. The form works fine, except for the reset button. And now that you mention the POST, I guess it makes sense why it's not showing any output. The blank page is "phpform.ph p." But I guess it wouldn't show anything if I don't put the POSTs in it.
Nov 6 '07 #3
ak1dnar
1,584 Recognized Expert Top Contributor
Sorry. The form works fine, except for the reset button. And now that you mention the POST, I guess it makes sense why it's not showing any output. The blank page is "phpform.ph p." But I guess it wouldn't show anything if I don't put the POSTs in it.
Well the reason is Like this; after fetching the form element properties from the text file, your first page will print like this;
Expand|Select|Wrap|Line Numbers
  1. <form action="phpform.php" method=POST>
  2. <p>Choose One of These<br>
  3. <input type="checkbox" name="shoe" id="shoe" value="true"><label for="shoe">shoe</label>
  4. <input type="checkbox" name="hair" id="hair" value="true"><label for="hair">hair</label>
  5. <p>Choose One<br>
  6. <input type="radio" name="Choose One" id="Choose One-3" value="3"><label for="Choose One-3">3</label>
  7. <input type="radio" name="Choose One" id="Choose One-6" value="6"><label for="Choose One-6">6</label>
  8. <p><label for="Comments">Comments</label><br>
  9. <p><textarea id="Comments" name="Comments" rows="4" cols="50"></textarea>
  10. <p><label for="Select">Select: </label><select name="Select" id="Select"><option></option>
  11. <option value="18-29">18-29</option>
  12. <option value="30-49">30-49</option>
  13. <option value="50-75">50-75</option>
  14. </select><p><label for="Please type your name">Please type your name: </label><input type="text" id="Please type your name" name="Please type your name">
  15. <p><input type=submit name=submit value="SUBMIT"></form>
  16. <input type=reset value="Reset">
  17. </form>
On the phpform.php side, you can print the form inputs in this way,
Expand|Select|Wrap|Line Numbers
  1. echo $_POST['Comments'];
  2.  
BUT, you won't be able get the form input for this field;

Expand|Select|Wrap|Line Numbers
  1. <input type="text" id="Please type your name" name="Please type your name">
Like this

Expand|Select|Wrap|Line Numbers
  1. echo $_POST['Please type your name'];
Problem is with the white spaces on the form "field Name" property.

but After changing this line on the text file
textbox = Please_type_you r_name

you can get the out put like this'
Expand|Select|Wrap|Line Numbers
  1. echo $_POST['Please_type_your_name'];
is this clear?
Nov 7 '07 #4
hotrod57
7 New Member
This is very helpful, thanks a lot!
Nov 7 '07 #5
ak1dnar
1,584 Recognized Expert Top Contributor
This is very helpful, thanks a lot!
Welcome anytime, Good luck ! :)
Nov 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4122
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the PrintDialog control under a security setting with only SafePrinting allowed. I have attached a sample project that I am using to try to accomplish this. The print dialog appears, but when I press the Print button, I get an exception (at the end...
9
1616
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the PrintDialog control under a security setting with only SafePrinting allowed. I have attached a sample project that I am using to try to accomplish this. The print dialog appears, but when I press the Print button, I get an exception (at the end...
9
367
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the PrintDialog control under a security setting with only SafePrinting allowed. I have attached a sample project that I am using to try to accomplish this. The print dialog appears, but when I press the Print button, I get an exception (at the end...
0
1210
by: plang | last post by:
:confused: I created a travel request form that allows multiple travelers and multiple legs per request. I have a standard form view that collects the traveler info from a main form and fills in the standard form view with the applicable data. Now I need to be able to print one standard form for each traveler with only one leg of travel per standard form. I created the master table for the traveler and a master table for the itinerary leg...
18
11322
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I move the page to the web server, I get the error "Settings to access printer...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10667
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10422
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9222
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3885
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.