473,511 Members | 10,195 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(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>[/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 2005
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.php" 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.php." 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.php." 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_your_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
4084
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...
9
1602
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...
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...
0
1189
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...
18
11264
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...
0
7245
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,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
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,...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7512
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...
0
5671
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,...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
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.