Form submit is not sending any POST data

11,193

Simple, because your form fields don't have name attributes, see below

<form name="formBillingOwner" id="formBillingOwner" method="POST" action="/dla.php">
    <input type="text" id="lastCustomNavSelected" value="<?php echo      $lastCustomNavSelected; ?>" />
    <input type="text" id="selectedBillingOwner" value="<?php echo $selectedBillingOwner; ?>" />
  </form>

Add names to them, for example:

<form name="formBillingOwner" id="formBillingOwner" method="POST" action="/dla.php">
    <input type="text" id="lastCustomNavSelected" name="lastCustomNavSelected" value="<?php echo      $lastCustomNavSelected; ?>" />
    <input type="text" id="selectedBillingOwner" name="selectedBillingOwner" value="<?php echo $selectedBillingOwner; ?>" />
  </form>

Note: Probably your jQuery assignments need to be fixed too but if that was the only issue then atleast a wrong value should have been POSTed to PHP, hence that is not the issue.

Share:
11,193
darnit78
Author by

darnit78

Updated on June 05, 2022

Comments

  • darnit78
    darnit78 almost 2 years

    On my web page, when I press the "Add Customer" link, the following happens:

    • the onclick handler is called, which
      • sets values into the forms two text fields
      • displays an alert (at this point you can see the new values in the text fields on the screen)
      • calls the form's submit button (Note: the form submits back to it's own PHP file)
    • The same php file is called, but there are no POST values received
      • I've verified this with
        • the code in the first line that counts the values in $_POST then displays later
        • using fiddler to look at the request sent to the page

    I've done this type of thing numerous times before with no problems. I've copied this code to two different web servers (linux, apache) with the same result. It's probably a minor problem but I can't find it.

    I've stripped out a whole bunch of code to get down to this little bit, but haven't figured out why no POST values are being sent.

    You can see a working copy of this at http://www.daleann.org/dla.php. The only thing need besides the code below is /js/jquery.min.js.

    Thanks for your help.

    <?php
    $pc=count($_POST)."<br />".date("H:i:s");
    ?>
    <html>
    <head>
    <script src="/js/jquery.min.js" /></script>
    <script type="text/javascript">
    $(document).ready(function() {
      alert("inside docReady");
      $(document).on('click', "a.menuBillingOwner", function() {
        $("#selectedBillingOwner").val("11");
        $("#lastCustomNavSelected").val("selectedBillingOwner");
        alert("selectedBillingOwner = "+document.forms['formBillingOwner'].elements['selectedBillingOwner'].value);
        document.forms['formBillingOwner'].submit();
      });
    });
    </script>
    </head>
    <body>
      <ul id="menuBillingOwner">
        <li><a href='#' id='menuBillingOwnerAdd' class='menuBillingOwner'>Add Customer</a></li>
      </ul>
      <?php
      $lastCustomNavSelected = $selectedBillingOwner = "";
      if (count($_POST) > 0 && isset($_POST['selectedBillingOwner'])) {
         $lastCustomNavSelected = "selectedBillingOwner";
         $selectedBillingOwner = $_POST['selectedBillingOwner'];
      }
      ?>
      <?php echo "pc = ".$pc."<br />\n"; ?>
      <form name="formBillingOwner" id="formBillingOwner" method="POST" action="/dla.php">
        <input type="text" id="lastCustomNavSelected" value="<?php echo      $lastCustomNavSelected; ?>" />
        <input type="text" id="selectedBillingOwner" value="<?php echo $selectedBillingOwner; ?>" />
      </form>
    </body>
    </html>
    
  • Amadan
    Amadan over 10 years
    "Don't add sugar into your coffee, it will become sweet if you do it." Well duh, I wouldn't be doing it if I didn't want it sweet. :P
  • darnit78
    darnit78 over 10 years
    Thank you!! I figured it would something minor and stupid. Now don't I feel silly!! I'd be more embarrassed if I told you how long I've been doing web pages. After reading your answer, I thought to myself "I don't always include the 'name' attribute", but they are there in other pages that I've looked at.
  • Hanky Panky
    Hanky Panky over 10 years
    Cheers, happens to all of us
  • Rohit Nandi
    Rohit Nandi over 2 years
    you saved my job :-D @HankyPanky