PHP with html form elements to an order page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • txguy
    New Member
    • Aug 2007
    • 22

    PHP with html form elements to an order page

    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 ...

    [code=html]

    <input type="checkbox" name="C04001" id="C04001" value=1 descrip="size, color, partnum, weight, class, texture, hardware" item="04001" rice="4.97" onclick="totalC heckboxes(this) ;" readonly>

    [/code]

    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.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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:
    [code=html]
    <!-- --------------------------¬ -->
    <input type="checkbox" name="parts[C04001]" id="C04001" value=1 descrip="size, color, partnum, weight, class, texture, hardware" item="04001" rice="4.97" onclick="totalC heckboxes(this) ;" readonly="reado nly" />
    [/code]

    Then in your PHP:
    [code=php]
    foreach( $_POST['parts'] as $name => $checked )
    {
    // Output / Processing goes here.

    // Debug
    echo $name, '<br />';
    }
    [/code]

    Comment

    • txguy
      New Member
      • Aug 2007
      • 22

      #3
      adding the element name change to htm page one works ok, and I have created a html page two with the following php ...

      [code=php]

      <?php

      $Item=$_GET["item"];
      $Description=$_ GET["descrip"];
      $UnitPrice=$_GE T["price"];
      $SubTotal=$_GET["AllColstot al"];

      foreach( $_POST['parts'] as $name => $checked )
      {

      // Output / Processing goes here.

      <!--- ORDER FORM --->

      }

      ?>

      [/code]

      but it doesnt post from page one.

      how should the submit line read on page one??
      Last edited by pbmods; Aug 26 '07, 06:28 PM. Reason: Changed [php=code] to [code=php].

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, TX.

        You'll need to make sure that each checkbox is named properly:
        [code=html]
        <input type="checkbox" name="parts[C04001]" ... />
        <input type="checkbox" name="parts[C04002]" ... />
        .
        .
        .
        [/code]

        For more information, have a look at this document.

        Comment

        • txguy
          New Member
          • Aug 2007
          • 22

          #5
          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 ...

          [code=html]

          <form action="pop.php "method="po st">
          and also tried it this way
          <form action="pop.htm "method="po st">

          <input type="submit">

          [/code]

          why wont the submit button call page two????????


          thanks

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            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.

            Comment

            • txguy
              New Member
              • Aug 2007
              • 22

              #7
              when I try

              [code=php]

              <?php
              echo $_POST['descrip'];
              echo $_REQUEST['price'];

              import_request_ variables('p', 'p_');
              echo $p_descrip;


              ?>
              [/code]

              all I get is the form with no data.
              thanks

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, TXGuy.

                Try this:
                [code=php]
                print_r($_POST) ;
                [/code] to see what, if any, input you're getting from the form.

                Comment

                • txguy
                  New Member
                  • Aug 2007
                  • 22

                  #9
                  with the following as my second page ...
                  [code=php]
                  <?php
                  $descrip = $_POST['descrip'];
                  $price = $_POST['price'];

                  echo $descrip, '<br />';

                  print_r($_POST) ;

                  import_request_ variables('p', 'p_');
                  echo $p_descrip;

                  echo "You ordered ". $descrip . " " . $price . ".<br />";
                  echo "WOOHOO!";

                  ?>[/code]

                  I get the java produced totals from page one
                  Code:
                  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 .
                  WOOHOO!
                  none of the checkbox data, checked or unchecked is coming thru

                  ?????

                  Comment

                  • pbmods
                    Recognized Expert Expert
                    • Apr 2007
                    • 5821

                    #10
                    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:
                    [code=php]
                    session_start() ;
                    foreach( $_POST as $_key => $_val )
                    {
                    $_SESSION[$_key] => $_val;
                    }
                    [/code]

                    And at the top of page two:
                    [code=php]
                    session_start() ;
                    print_r($_SESSI ON);
                    [/code]

                    Comment

                    • txguy
                      New Member
                      • Aug 2007
                      • 22

                      #11
                      got the following

                      Parse error: syntax error, unexpected T_DOUBLE_ARROW on line 9

                      [code=php]
                      <html>
                      <head>


                      <?php
                      session_start() ;
                      foreach( $_POST as $_key => $_val )
                      {
                      $_SESSION[$_key] => $_val;
                      }
                      ?>

                      [/code]

                      Comment

                      • pbmods
                        Recognized Expert Expert
                        • Apr 2007
                        • 5821

                        #12
                        Heya, TX.

                        Originally posted by txguy
                        got the following

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

                        [code=php]
                        <html>
                        <head>


                        <?php
                        session_start() ;
                        foreach( $_POST as $_key => $_val )
                        { // No > here ----¬
                        $_SESSION[$_key] = $_val;
                        }
                        ?>

                        [/code]

                        Comment

                        • txguy
                          New Member
                          • Aug 2007
                          • 22

                          #13
                          thanks very much for your help.

                          got a session error

                          Warning: session_start() [function.sessio n-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.sessio n-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

                          [code=php]
                          <html>
                          <head>


                          <?php
                          session_start() ;
                          foreach( $_POST as $_key => $_val )
                          {
                          $_SESSION[$_key] = $_val;
                          }
                          ?>

                          <script type="text/javascript">



                          function totalCheckboxes (checkField) {

                          //Determine the column
                          var column = checkField.name .substr(1,2);

                          var columnTotal = 0;
                          var columnCount = 0;

                          //Itterate through all the checkboxes in the column
                          for (i=1; i<=110; i++) {

                          var row = '00'+i;
                          fieldID = 'C'+column+row. substr(row.leng th-3)

                          //only check fields that exist
                          if (chkObj = document.getEle mentById(fieldI D)) {

                          //Add price if field is checked
                          if (chkObj.checked ) {
                          columnCount++;
                          columnTotal = parseFloat(colu mnTotal) + parseFloat(chkO bj.price);
                          }
                          }

                          }

                          //Enter the totals for the current column
                          document.getEle mentById('Col'+ column+'count') .value = columnCount;
                          document.getEle mentById('Col'+ column+'total') .value = columnTotal.toF ixed(2);

                          //Add the totals from each column
                          var grandTotal = 0;
                          var grandCount = 0;
                          for (i=1; i<=10; i++) {
                          column = (i<10)?'0'+i:i;
                          columnCount = document.getEle mentById('Col'+ column+'count') .value;
                          columnTotal = document.getEle mentById('Col'+ column+'total') .value;

                          grandCount = parseFloat(gran dCount) + parseFloat((col umnCount)?colum nCount:0);
                          grandTotal = parseFloat(gran dTotal) + parseFloat((col umnTotal)?colum nTotal:0);
                          }

                          //Enter the grand totals
                          document.getEle mentById('AllCo lscount').value = grandCount;
                          document.getEle mentById('AllCo lstotal').value = "$ "+grandTotal.to Fixed(2);

                          document.getEle mentById('AllCo lscountsum').va lue = grandCount;
                          document.getEle mentById('AllCo lstotalsum').va lue = "$ "+grandTotal.to Fixed(2);

                          }


                          </script>


                          </head>

                          <body bgcolor="#FFFFC E">
                          [/code]

                          Comment

                          • pbmods
                            Recognized Expert Expert
                            • Apr 2007
                            • 5821

                            #14
                            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

                            [code=php]
                            <?php
                            session_start() ;
                            foreach( $_POST as $_key => $_val )
                            {
                            $_SESSION[$_key] = $_val;
                            }
                            ?>
                            <html>
                            <head>
                            .
                            .
                            .
                            [/code]

                            Comment

                            • txguy
                              New Member
                              • Aug 2007
                              • 22

                              #15
                              thanks, page1 works but get the following from page2 ...

                              Warning: session_start() [function.sessio n-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

                              [code=php]
                              <html><body>

                              <?php

                              session_start() ;

                              print_r($_SESSI ON);

                              print_r($_POST) ;

                              ?>

                              </body></html>
                              [/code]

                              I really appreciate your help

                              Comment

                              Working...