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

Re: POST form via XMLHttpRequest

Expand Messages
  • Thomas S. Sha
    ... Thanks for pointing this out. Some of the updates to setForm( ) in the next release will: * Allow GET as well as POST submissions. * Exclude fields with
    Message 1 of 11 , Apr 28, 2006
    • 0 Attachment
      --- 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?

      Thanks for pointing this out.

      Some of the updates to setForm( ) in the next release will:

      * Allow GET as well as POST submissions.
      * Exclude fields with empty values.
      * Exclude input type="button" and "reset" values.
      * Exclude fields marked "disabled".

      I haven't yet encountered the id v. name attr use case. I'll log this
      for review.

      Regards,
      Thomas
    • Matt Warden
      ... Name is a required attribute in form fields (except submit and reset buttons). I would disagree with the YUI library encouraging the use of invalid
      Message 2 of 11 , Apr 28, 2006
      • 0 Attachment
        On 4/28/06, 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?

        Name is a required attribute in form fields (except submit and reset
        buttons). I would disagree with the YUI library encouraging the use of
        invalid (x)html.

        --
        Matt Warden
        Miami University
        Oxford, OH, USA
        http://mattwarden.com


        This email proudly and graciously contributes to entropy.
      • Thomas S. Sha
        ... Sorry, I misread this email - setForm( ) requires the name attribute to be populated instead of id for reason mentioned by Matt Warden. Regards, Thomas
        Message 3 of 11 , Apr 28, 2006
        • 0 Attachment
          --- 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
        • Michael Newton
          ... 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.
          Message 4 of 11 , Apr 28, 2006
          • 0 Attachment
            --- 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?
          • Michael Newton
            ... submitted ... an ... Actually, DTDs for both HTML 4 and XHTML 1.1 claim that name is an #IMPLIED attribute for all form elements. The only suggestion
            Message 5 of 11 , Apr 28, 2006
            • 0 Attachment
              --- In ydn-javascript@yahoogroups.com, "Matt Warden" <mwarden@...> wrote:
              >
              > On 4/28/06, 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?
              >
              > Name is a required attribute in form fields (except submit and reset
              > buttons). I would disagree with the YUI library encouraging the use of
              > invalid (x)html.
              >
              > --
              > Matt Warden
              > Miami University
              > Oxford, OH, USA
              > http://mattwarden.com
              >
              >
              > This email proudly and graciously contributes to entropy.
              >

              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.

              <!ELEMENT INPUT - O EMPTY>
              <!ATTLIST INPUT
                %attrs;
                type        %InputType;    TEXT
                name        CDATA          #IMPLIED
                value       CDATA          #IMPLIED
              ...
              >


              In the HTML 4 specification, a "successful control" is defined:

              A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.

              So it would seem that unsuccessful controls (those which are not submitted) do not require a name attribute.


              Speaking of invalid HTML, how about this "rich text editor" for online posting!
            • Thomas S. Sha
              ... submitted ... only an ... I wasn t able to replicate the condition you experienced with a form field containing an id rather than a name attr. Is this
              Message 6 of 11 , Apr 28, 2006
              • 0 Attachment
                --- 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
              • Matt Warden
                ... Hash: SHA1 ... It is implied because submit and reset buttons are exceptions. Therefore the DTD must not require name attribute for INPUT elements lest it
                Message 7 of 11 , Apr 28, 2006
                • 0 Attachment
                  -----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-----
                • Michael Newton
                  ... I toally see your point, but... the attribute is not required for select, textarea, or button elements either.
                  Message 8 of 11 , Apr 28, 2006
                  • 0 Attachment
                    --- 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 9 of 11 , Apr 28, 2006
                    • 0 Attachment
                      --- 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 10 of 11 , Apr 28, 2006
                      • 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>


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