473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PHP with html form elements to an order page

22
Hello and thanks. have a html form with 1210 checkboxes that define item description, number and price. would like to find a PHP script that reads these values when the checkbox is checked and then creates and displays a pre-filled order form with Item number, description, unit price and adds a text box where the user can select quantity.

each item checkbox data looks like this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. <input type="checkbox" name="C04001" id="C04001" value=1 descrip="size, color, partnum,  weight,  class,  texture, hardware" item="04001" rice="4.97" onclick="totalCheckboxes(this);" readonly>
  3.  
  4.  
we are totaling checkboxes on page one and may use a form mailer to track interest, but we really need the second page running on our web server.

thanks again for your help.
Aug 26 '07 #1
18 1878
pbmods
5,821 Expert 4TB
Heya, txguy.

When a checkbox is submitted with form data, it will not show up at all if it is unchecked, and it will be included with a value of 'ON' if it is checked.

Probably your best bet would be to create a sub-array and then loop through it:
Expand|Select|Wrap|Line Numbers
  1. <!-- --------------------------¬             -->
  2. <input type="checkbox" name="parts[C04001]" id="C04001" value=1 descrip="size, color, partnum,  weight,  class,  texture, hardware" item="04001" rice="4.97" onclick="totalCheckboxes(this);" readonly="readonly" />
  3.  
Then in your PHP:
Expand|Select|Wrap|Line Numbers
  1. foreach( $_POST['parts'] as $name => $checked )
  2. {
  3.     // Output / Processing goes here.
  4.  
  5.     // Debug
  6.     echo $name, '<br />';
  7. }
  8.  
Aug 26 '07 #2
txguy
22
adding the element name change to htm page one works ok, and I have created a html page two with the following php ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3.  
  4. $Item=$_GET["item"];
  5. $Description=$_GET["descrip"];
  6. $UnitPrice=$_GET["price"];
  7. $SubTotal=$_GET["AllColstotal"];
  8.  
  9. foreach( $_POST['parts'] as $name => $checked )
  10. {
  11.  
  12.     // Output / Processing goes here.
  13.  
  14. <!--- ORDER FORM --->
  15.  
  16. }
  17.  
  18. ?>
  19.  
  20.  
but it doesnt post from page one.

how should the submit line read on page one??
Aug 26 '07 #3
pbmods
5,821 Expert 4TB
Heya, TX.

You'll need to make sure that each checkbox is named properly:
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="parts[C04001]" ... />
  2. <input type="checkbox" name="parts[C04002]" ... />
  3. .
  4. .
  5. .
  6.  
For more information, have a look at this document.
Aug 26 '07 #4
txguy
22
got that part thanks ... I have updated all pageone names to include "parts[xxxxx] and have page one is working fine ... I've built page two with the php code in the top with the table layout and input field names using the $name and the loop function you recommended ... I've saved this file as both name.php and name.htm neither or working ... my form instruction on page one and my submit are as follows ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. <form action="pop.php"method="post">
  3.     and also tried it this way
  4. <form action="pop.htm"method="post">
  5.  
  6. <input type="submit">
  7.  
  8.  
why wont the submit button call page two????????


thanks
Aug 26 '07 #5
pbmods
5,821 Expert 4TB
Heya, TX.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Aug 26 '07 #6
txguy
22
when I try

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.    echo $_POST['descrip'];
  4.    echo $_REQUEST['price'];
  5.  
  6. import_request_variables('p', 'p_');
  7.    echo $p_descrip;
  8.  
  9.  
  10. ?>
  11.  
all I get is the form with no data.
thanks
Sep 1 '07 #7
pbmods
5,821 Expert 4TB
Heya, TXGuy.

Try this:
Expand|Select|Wrap|Line Numbers
  1. print_r($_POST);
  2.  
to see what, if any, input you're getting from the form.
Sep 1 '07 #8
txguy
22
with the following as my second page ...
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $descrip = $_POST['descrip'];
  3. $price = $_POST['price'];
  4.  
  5. echo $descrip, '<br />';
  6.  
  7. print_r($_POST);
  8.  
  9. import_request_variables('p', 'p_');
  10.    echo $p_descrip;
  11.  
  12. echo "You ordered ". $descrip . " " . $price . ".<br />";
  13. echo "WOOHOO!";
  14.  
  15. ?>
I get the java produced totals from page one
Expand|Select|Wrap|Line Numbers
  1. Array ( [AllColscount] => 1 [selections] => Tarps [AllColstotal] => $ 68.77 [Col01count] => 0 [Col02count] => 0 [Col03count] => 0 [Col04count] => 0 [Col05count] => 0 [Col06count] => 0 [Col07count] => 1 [Col08count] => 0 [Col09count] => 0 [Col10count] => 0 [C07079] => 1 [Col01total] => 0.00 [Col02total] => 0.00 [Col03total] => 0.00 [Col04total] => 0.00 [Col05total] => 0.00 [Col06total] => 0.00 [Col07total] => 68.77 [Col08total] => 0.00 [Col09total] => 0.00 [Col10total] => 0.00 [AllColscountsum] => 1 [AllColstotalsum] => $ 68.77 [view_x] => 26 [view_y] => 11 ) You ordered .
  2. WOOHOO! 
  3.  
none of the checkbox data, checked or unchecked is coming thru

?????
Sep 1 '07 #9
pbmods
5,821 Expert 4TB
Heya, TX.

$_POST is not persistent. Your checkbox data will only be available to the page you're submitting the form to.

Try adding this to the top of your first page:
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. foreach( $_POST as $_key => $_val )
  3. {
  4.     $_SESSION[$_key] => $_val;
  5. }
  6.  
And at the top of page two:
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. print_r($_SESSION);
  3.  
Sep 1 '07 #10
txguy
22
got the following

Parse error: syntax error, unexpected T_DOUBLE_ARROW on line 9

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4.  
  5. <?php
  6. session_start();
  7. foreach( $_POST as $_key => $_val )
  8. {
  9.     $_SESSION[$_key] => $_val;
  10. }
  11. ?>
  12.  
  13.  
Sep 1 '07 #11
pbmods
5,821 Expert 4TB
Heya, TX.

got the following

Parse error: syntax error, unexpected T_DOUBLE_ARROW on line 9
Oops. Sorry about that. Try this:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4.  
  5. <?php
  6. session_start();
  7. foreach( $_POST as $_key => $_val )
  8. {  //  No > here ----¬
  9.     $_SESSION[$_key] = $_val;
  10. }
  11. ?>
  12.  
  13.  
Sep 1 '07 #12
txguy
22
thanks very much for your help.

got a session error

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ihh-2693/it-happens-here-www/test/st/sct-00.php:5) in /home/ihh-2693/it-happens-here-www/test/st/sct-00.php on line 6

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ihh-2693/it-happens-here-www/test/st/sct-00.php:5) in /home/ihh-2693/it-happens-here-www/test/st/sct-00.php on line 6

heres the code from page1

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4.  
  5. <?php
  6. session_start();
  7. foreach( $_POST as $_key => $_val )
  8. {
  9.     $_SESSION[$_key] = $_val;
  10. }
  11. ?>
  12.  
  13. <script type="text/javascript">
  14.  
  15.  
  16.  
  17. function totalCheckboxes(checkField) {
  18.  
  19.     //Determine the column
  20.     var column = checkField.name.substr(1,2);
  21.  
  22.     var columnTotal = 0;
  23.     var columnCount = 0;
  24.  
  25.     //Itterate through all the checkboxes in the column
  26.     for (i=1; i<=110; i++) {
  27.  
  28.       var row = '00'+i;
  29.       fieldID = 'C'+column+row.substr(row.length-3)
  30.  
  31.       //only check fields that exist
  32.       if (chkObj = document.getElementById(fieldID)) {
  33.  
  34.         //Add price if field is checked
  35.         if (chkObj.checked) {
  36.           columnCount++;
  37.           columnTotal = parseFloat(columnTotal) + parseFloat(chkObj.price);
  38.         }
  39.       }
  40.  
  41.     }
  42.  
  43.     //Enter the totals for the current column
  44.     document.getElementById('Col'+column+'count').value = columnCount;
  45.     document.getElementById('Col'+column+'total').value = columnTotal.toFixed(2);
  46.  
  47.     //Add the totals from each column
  48.     var grandTotal = 0;
  49.     var grandCount = 0;
  50.     for (i=1; i<=10; i++) {
  51.       column = (i<10)?'0'+i:i;
  52.       columnCount = document.getElementById('Col'+column+'count').value;
  53.       columnTotal = document.getElementById('Col'+column+'total').value;
  54.  
  55.       grandCount = parseFloat(grandCount) + parseFloat((columnCount)?columnCount:0);
  56.       grandTotal = parseFloat(grandTotal) + parseFloat((columnTotal)?columnTotal:0);
  57.     }
  58.  
  59.     //Enter the grand totals
  60.     document.getElementById('AllColscount').value = grandCount;
  61.     document.getElementById('AllColstotal').value = "$ "+grandTotal.toFixed(2);
  62.  
  63.     document.getElementById('AllColscountsum').value = grandCount;
  64.     document.getElementById('AllColstotalsum').value = "$ "+grandTotal.toFixed(2);
  65.  
  66. }
  67.  
  68.  
  69. </script>
  70.  
  71.  
  72. </head>
  73.  
  74. <body bgcolor="#FFFFCE">
  75.  
Sep 1 '07 #13
pbmods
5,821 Expert 4TB
Heya, TX.

My goodness. I feel so silly making all of these mistakes that I should know better!

session_start() has to go before your script outputs anything. You'll want to do this instead, and this time, it really should work :P

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. foreach( $_POST as $_key => $_val )
  4. {
  5.     $_SESSION[$_key] = $_val;
  6. }
  7. ?>
  8. <html>
  9. <head>
  10. .
  11. .
  12. .
  13.  
Sep 1 '07 #14
txguy
22
thanks, page1 works but get the following from page2 ...

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ihh-2693/it-happens-here-www/test/st/popchecks.php:3) in /home/ihh-2693/it-happens-here-www/test/st/popchecks.php on line 5
Array ( ) Array ( [AllColscount] => 2 [selections] => Tarps [AllColstotal] => $ 147.20 [Col01count] => 0 [Col02count] => 0 [Col03count] => 1 [Col04count] => 1 [Col05count] => 0 [Col06count] => 0 [Col07count] => 0 [Col08count] => 0 [Col09count] => 0 [Col10count] => 0 [C03074] => 1 [C04074] => 1 [Col01total] => 0.00 [Col02total] => 0.00 [Col03total] => 73.60 [Col04total] => 73.60 [Col05total] => 0.00 [Col06total] => 0.00 [Col07total] => 0.00 [Col08total] => 0.00 [Col09total] => 0.00 [Col10total] => 0.00 [AllColscountsum] => 2 [AllColstotalsum] => $ 147.20 [view_x] => 17 [view_y] => 7 )

here's page2 code

Expand|Select|Wrap|Line Numbers
  1. <html><body>
  2.  
  3. <?php
  4.  
  5. session_start();
  6.  
  7. print_r($_SESSION);
  8.  
  9. print_r($_POST);
  10.  
  11. ?>
  12.  
  13. </body></html>
  14.  
I really appreciate your help
Sep 1 '07 #15
txguy
22
if I delete the

Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.  
from page2, I dont get the session error, but I still dont get the input data element from page1 just the array totals from page1

Array ( [AllColscount] => 1 [selections] => Tarps [AllColstotal] => $ 149.39 [Col01count] => 0 [Col02count] => 0 [Col03count] => 0 [Col04count] => 0 [Col05count] => 1 [Col06count] => 0 [Col07count] => 0 [Col08count] => 0 [Col09count] => 0 [Col10count] => 0 [C05079] => 1 [Col01total] => 0.00 [Col02total] => 0.00 [Col03total] => 0.00 [Col04total] => 0.00 [Col05total] => 149.39 [Col06total] => 0.00 [Col07total] => 0.00 [Col08total] => 0.00 [Col09total] => 0.00 [Col10total] => 0.00 [AllColscountsum] => 1 [AllColstotalsum] => $ 149.39 [view_x] => 22 [view_y] => 3 )

????????
Sep 1 '07 #16
pbmods
5,821 Expert 4TB
Heya, TX.

Similarly to page 1, on page 2, you have to call session_start() before your script outputs anything.
Sep 1 '07 #17
txguy
22
eliminated the html code, just php and I only get the original array values for the total functions from page1, stil dont get the checkbox element values; descrip, price, name
Sep 2 '07 #18
pbmods
5,821 Expert 4TB
Heya, TX.

A similar problem came up in this thread.
Sep 2 '07 #19

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

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
10
by: Rithish | last post by:
I want to emulate paging in an HTML document. something like, ------------------------- | | | <DIV> | | | | <TABLE></TABLE>...
22
by: Luke | last post by:
Elements with name attribute: form, input, textarea, a, frame, iframe, button, select, map, meta, applet, object, param, img (if you know more reply...) Methods of addresing html elements:...
5
by: Brian Kitt | last post by:
I have a C# application that builds dynamic HTML and renders it. Because it is rendered in this way, the input controls are not server controls. I write the entire page, which has a variable...
79
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the...
3
by: Samuel Shulman | last post by:
I would like to refer to HTML elements from my ASP.NET code do they have to be server side If yes then I can I set their html name for the POST method Thank you, Samuel
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.