Loading ...
Sorry, an error occurred while loading the content.

1074Re: POST form via XMLHttpRequest

Expand Messages
  • Michael Newton
    Apr 28 5:19 PM
    • 0 Attachment
      --- In ydn-javascript@yahoogroups.com, "Thomas S. Sha" <tsha@...> wrote:
      >
      > --- In ydn-javascript@yahoogroups.com, "Michael Newton"
      > mnewton32@ wrote:
      > >
      > > --- In ydn-javascript@yahoogroups.com, "Thomas S. Sha" <tsha@> wrote:
      > > >
      > > > --- In ydn-javascript@yahoogroups.com, "Michael Newton"
      > > > <mnewton32@> wrote:
      > > > >
      > > > > When posting a form, all the form elements are submitted, even the
      > > > > ones without a name. Traditionally, only named elements are
      > submitted
      > > > > (using the name, not the ID), allowing for input elements with
      > only an
      > > > > ID to be part of the form, but not part of the submission.
      > > > >
      > > > > Will this be fixed in the future?
      > > > >
      > > >
      > > > Sorry, I misread this email - setForm( ) requires the name attribute
      > > > to be populated instead of id for reason mentioned by Matt Warden.
      > > >
      > > > Regards,
      > > > Thomas
      > > >
      > >
      > > Okay, and if the name attribute isn't populated, what should happen?
      > > I agree whole-heartedly that these inputs without name attributes are
      > > invalid HTML. So why do they get posted, using the ID attribute?
      > >
      >
      > I wasn't able to replicate the condition you experienced with a form
      > field containing an id rather than a name attr. Is this happening
      > with a specific type of input?
      >
      > Can you send me the form html so I can take a further look?
      >
      > Regards,
      > Thomas
      >

      Hmm, I must have been mistaken about it getting sent with the ID attribute: it gets sent without a name at all.  The important thing is that it's messing up my server-side code!  If you have a form containing an input with only an ID specified (no name) and watch the headers as they are sent out, you see this, for example:
      POST /test.php HTTP/1.1
      Host: localhost:8080
      User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-CA; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2
      Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
      Accept-Language: en-ca,en-ie;q=0.9,en-gb;q=0.7,en-nz;q=0.6,en-au;q=0.4,en;q=0.3,en-us;q=0.1
      Accept-Encoding: gzip,deflate
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
      Keep-Alive: 300
      Connection: keep-alive
      Content-Type: application/x-www-form-urlencoded
      Content-Length: 22
      Cookie: tablewidth=800; style=Yahoo
      Pragma: no-cache
      Cache-Control: no-cache
      test=name&=no%20name&=

      This is using the following PHP:
      <?php
      if ($_POST) {
      echo 'got posted';
      exit;
      }
      ?>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3.org/TR/html4/strict.dtd">
      <html lang = "en">
      <head>
      <title>Test</title>
      <script type="text/javascript" src="yui/YAHOO.js"></script>
      <script type="text/javascript" src="yui/connection.js"></script>
      <script type="text/javascript" src="yui/event.js"></script>
      <script type="text/javascript">
      <!--
      function submit_this() {
          var callback = {
              success: submit_success,
              failure: null,
              argument: null
          }
          YAHOO.util.Connect.setForm('testform');
          YAHOO.util.Connect.asyncRequest('POST', '<?php echo $_SERVER['PHP_SELF']?>', callback, null);
      }

      function submit_success(ret) {
          alert(ret.responseText);
      }

      YAHOO.util.Event.addListener(window, 'load', function() {
          YAHOO.util.Event.addListener(
      document.getElementById('submitter'), 'click', submit_this);
      });
      // -->
      </script>
      </head>

      <body>
      <form name="testform" id="testform" action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
      <div>
      <input name="test" id="test" value="name">
      <input id="test2" value="no name">
      <button type="button" id="submitter">submit</button>
      </div>
      </form>
      </body>


    • Show all 11 messages in this topic