3 Replies Latest reply on Aug 26, 2011 3:31 PM by tkaranov

    How to examine the HTTP Service ResultEvent.result object

    tkaranov

      My Flex 4 project contains a contact form that works when properly completed

      However, I want to add an alert to let the user know whether the form was submitted sucessfully or if it failed because of missing information.

       

      The server side script (FormMail.pl) returns either  "Thank You" or  "Error:BlankFields" indicating fields were left blank. See examples below:

       

      Network Monitor Response for "Sucessful" submission:

      HTTP/1.1 200 OK
      Date: Thu, 25 Aug 2011 17:07:27 GMT
      Server: Apache
      Transfer-Encoding: chunked
      Content-Type: text/html; charset=iso-8859-1

       

      <?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">  <head>    <title>Thank You</title><link rel="stylesheet" type="text/css" href="/css/nms.css" />     <style>       h1.title {                   text-align : center;                }     </style>  </head>  <body >    <h1 class="title">Thank You</h1>    <p>Below is what you submitted to info&#64;awningsofmarietta.com on Thursday, August 25, 2011 at 13:07:27</p>    <p><hr size="1" width="75%" /></p><p><b>rename:</b> adams</p><p><b>stonetype:</b> Single</p><p><b>nameFull:</b> adams</p><p><hr size="1" width="75%" /></p>        <hr size="1" width="75%" />        <p align="center">           <font size="-1">             <a href="http://nms-cgi.sourceforge.net/">FormMail</a>             &copy; 2001  London Perl Mongers           </font>        </p>        </body>       </html>

       

      Network Monitor Response for "Error" submission:

      HTTP/1.1 200 OK
      Date: Thu, 25 Aug 2011 17:14:09 GMT
      Server: Apache
      Transfer-Encoding: chunked
      Content-Type: text/html; charset=iso-8859-1

      <?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">  <head>   <title>Error: Blank Fields</title>    <style type="text/css">    <!--       body {              background-color: #FFFFFF;              color: #000000;             }       table {               background-color: #9C9C9C;             }       p.c2 {              font-size: 80%;              text-align: center;            }       tr.title_row  {                        background-color: #9C9C9C;                      }       tr.body_row   {                         background-color: #CFCFCF;                      }       th.c1 {               text-align: center;               font-size: 143%;             }       p.c3 {font-size: 80%; text-align: center}       div.c2 {margin-left: 2em}     -->    </style><link rel="stylesheet" type="text/css" href="/css/nms.css" />  </head>  <body>    <table border="0" width="600" summary="">      <tr class="title_row">        <th class="c1">Error: Blank Fields</th>      </tr>      <tr class="body_row">        <td>          <p>    The following fields were left blank in your submission form:</p><div class="c2">   <ul>     <li>rename</li>   </ul></div><p>    These fields must be filled in before you can successfully    submit the form.</p><p>    Please use your back button to return to the form and    try again.</p>          <hr size="1" />          <p class="c3">            <a href="http://nms-cgi.sourceforge.net/">FormMail</a>            &copy; 2001-2003 London Perl Mongers          </p>        </td>      </tr>    </table>  </body></html>

       

       

      I'm trying to use the ResultEvent to notify the User if the form was submitted or errored.

      I have the following function:

       

                  [Bindable]
                  private var myResult:XML;
             
                      public function showMailResults(event:ResultEvent):void {
                          myResult= XML(event.result.html.head);
                          Alert.show(event.result.html.head);
                      }

       

      I've tried several variations but they all simply display the text "[object  Object]".

       

      I can't figure out how to parse the event results to determine if the submission was successful or not.

      I had hoped I could use the ResultEvent to check for the "Thank You" in the <title> tag and show a "Success" Alert else show an Alert indicating the user failed to enter their email address.

       

      Despite seeing posts from many people using the same FormMail.pl script I've been unable to find a solution for communicating success or failure in any of the forums or tutorials so far.

        • 1. Re: How to examine the HTTP Service ResultEvent.result object
          Sree_D Level 2

          looks like the return format as per network monitor is text/html. Not sure if html is recieved properly in ResultEvent (is it supported ?). Verify the result format of the HttpService definition you are using else try returning an xml content with same message.

          1 person found this helpful
          • 2. Re: How to examine the HTTP Service ResultEvent.result object
            tkaranov Level 1

            Thanks for giving me the heads up that my response may not even be supported.  I'll dig into that.

            • 3. Re: How to examine the HTTP Service ResultEvent.result object
              tkaranov Level 1

              I've found that the resultFormat default value is object.

              • object The value returned is XML and is parsed as a tree of ActionScript objects. This is the default.

              This is what the results look like in the Network Monitor Tree View:

              good Response crop.png

              So I changed my function to display the <html><head><title> value and it now works.

               

              private var myResults:XML;

               

                              public function showMailResults(event:ResultEvent):void {                          

               

                              myResults=XML(event.result.html.head.title);

               

                              Alert.show(event.result.html.head.title);

               

                              }

               

              Nothing like spending 2 days fighting a problem that was so simple to fix!