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

How to Connection.setForm() encode in utf-8

Expand Messages
  • jeremymefford
    Hi all- I m having some difficulty with the connection.setForm() method. It s encoding my form via ISO-8859-1 instead of utf-8. I did:
    Message 1 of 4 , Apr 30, 2008
    • 0 Attachment
      Hi all-

      I'm having some difficulty with the connection.setForm() method. It's
      encoding my form via ISO-8859-1 instead of utf-8. I did:

      connection.initHeader("Content-Type","text/html; charset=utf-8");

      and that didn't do anything. Also, the page that the form is on has a
      <meta> tag defining it as UTF-8. Any help is greatly appreciated!

      Thanks-
      Jeremy
    • tssha
      ... If you are sending HTML form data via setForm, then change the initHeader() call to: var connection = YAHOO.util.Connect; connection.initHeader(
      Message 2 of 4 , Apr 30, 2008
      • 0 Attachment
        --- In ydn-javascript@yahoogroups.com, "jeremymefford"
        <jeremymefford@...> wrote:
        >
        > Hi all-
        >
        > I'm having some difficulty with the connection.setForm() method. It's
        > encoding my form via ISO-8859-1 instead of utf-8. I did:
        >
        > connection.initHeader("Content-Type","text/html; charset=utf-8");

        If you are sending HTML form data via setForm, then change the
        initHeader() call to:
        var connection = YAHOO.util.Connect;
        connection.initHeader(
        "Content-Type",
        "application/x-www-form-urlencoded; charset=UTF-8");

        Each valid form field name and label are subject to
        encodeURIComponent(), as well.

        N.B. This does not work for file upload transactions.

        Regards,
        Thomas
      • emmett_mclean
        The addition of this attribute fixes an issue with JSTLs where some tags do not support UTF-8 by default even if the
        Message 3 of 4 , Apr 30, 2008
        • 0 Attachment
          <form name="aForm" ENCTYPE="UTF-8" >

          The addition of this attribute fixes an issue with JSTLs where some
          tags do not support UTF-8 by default even if the context type for the
          page is UTF-8. See if it works for you.
        • jeremymefford
          So I finally found out what I needed to do. I m not quite sure exactly what the difference is between this and what I was trying to do earlier... I get
          Message 4 of 4 , May 1, 2008
          • 0 Attachment
            So I finally found out what I needed to do. I'm not quite sure
            exactly what the difference is between this and what I was trying to
            do earlier... I get confused when trying to send strange characters in
            the request. In any case, here's the code that I ended up with and it
            works like a charm.


            generatePostData: function(eForm) {
            var aElements = eForm.elements;
            var sPostData = "";
            for (var iter = 0;iter < aElements.length;iter++) {
            var currElement = aElements[iter];
            if (currElement.name) {
            if (currElement.name != "") {
            if (sPostData != "") {
            sPostData += "&";
            }
            sPostData += currElement.name + "=" +
            escape(currElement.value);
            }
            }
            }
            return sPostData;
            },

            Thanks for your help though.

            Best-
            Jeremy

            --- In ydn-javascript@yahoogroups.com, "jeremymefford"
            <jeremymefford@...> wrote:
            >
            > Hi all-
            >
            > I'm having some difficulty with the connection.setForm() method. It's
            > encoding my form via ISO-8859-1 instead of utf-8. I did:
            >
            > connection.initHeader("Content-Type","text/html; charset=utf-8");
            >
            > and that didn't do anything. Also, the page that the form is on has a
            > <meta> tag defining it as UTF-8. Any help is greatly appreciated!
            >
            > Thanks-
            > Jeremy
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.