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

Re: POST form via XMLHttpRequest

Expand Messages
  • Michael Newton
    ... I toally see your point, but... the attribute is not required for select, textarea, or button elements either.
    Message 1 of 11 , Apr 28, 2006
      --- In ydn-javascript@yahoogroups.com, Matt Warden <mwarden@...> wrote:
      >
      > -----BEGIN PGP SIGNED MESSAGE-----
      > Hash: SHA1
      >
      > Michael Newton wrote:
      > > Actually, DTDs for both HTML 4 and XHTML 1.1 claim that name is an
      > > #IMPLIED attribute for all form elements. The only suggestion
      > > otherwise is a comment in the DTD, which hardly seems normative to me.
      >
      > It is implied because submit and reset buttons are exceptions. Therefore
      > the DTD must not require name attribute for INPUT elements lest it call
      > all documents invalid if there are submit/reset buttons without the
      > optional name attribute. You might not find the comment normative, but
      > its presence in the specification is no accident.
      >
      >
      >
      > - --
      > Matt Warden
      > Miami University
      > Oxford, OH, USA
      > http://mattwarden.com
      >
      >
      > This email proudly and graciously contributes to entropy.
      > -----BEGIN PGP SIGNATURE-----
      > Version: GnuPG v1.4.1 (GNU/Linux)
      > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
      >
      > iD8DBQFEUo9qrI3LObhzHRMRAhcjAKDMx4MFoNbL0oic5eWaIDPlpASrCQCguop+
      > E0mdw51d0kJ3EF+0fZSac94=
      > =w1OX
      > -----END PGP SIGNATURE-----
      >

      I toally see your point, but... the attribute is not required for
      select, textarea, or button elements either.
    • Michael Newton
      ... Anyway, though it may appear otherwise, I don t want to get into an argument about HTML! If a form element is invalid (a point I don t concede!)
      Message 2 of 11 , Apr 28, 2006
        --- In ydn-javascript@yahoogroups.com, Matt Warden <mwarden@...> wrote:
        >
        > -----BEGIN PGP SIGNED MESSAGE-----
        > Hash: SHA1
        >
        > Michael Newton wrote:
        > > Actually, DTDs for both HTML 4 and XHTML 1.1 claim that name is an
        > > #IMPLIED attribute for all form elements. The only suggestion
        > > otherwise is a comment in the DTD, which hardly seems normative to me.
        >
        > It is implied because submit and reset buttons are exceptions. Therefore
        > the DTD must not require name attribute for INPUT elements lest it call
        > all documents invalid if there are submit/reset buttons without the
        > optional name attribute. You might not find the comment normative, but
        > its presence in the specification is no accident.
        >
        >
        >
        > - --
        > Matt Warden
        > Miami University
        > Oxford, OH, USA
        > http://mattwarden.com
        >
        >
        > This email proudly and graciously contributes to entropy.
        > -----BEGIN PGP SIGNATURE-----
        > Version: GnuPG v1.4.1 (GNU/Linux)
        > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
        >
        > iD8DBQFEUo9qrI3LObhzHRMRAhcjAKDMx4MFoNbL0oic5eWaIDPlpASrCQCguop+
        > E0mdw51d0kJ3EF+0fZSac94=
        > =w1OX
        > -----END PGP SIGNATURE-----
        >

        Anyway, though it may appear otherwise, I don't want to get into an
        argument about HTML! If a form element is "invalid" (a point I don't
        concede!) shouldn't it be ignored by the script? Instead, it is being
        submitted with its ID instead.
      • Michael Newton
        ... the ... attribute ... are ... Hmm, I must have been mistaken about it getting sent with the ID attribute: it gets sent without a name at all. The
        Message 3 of 11 , Apr 28, 2006
          --- 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>


        Your message has been successfully submitted and would be delivered to recipients shortly.