10 Replies Latest reply on Jun 15, 2009 10:54 AM by leybniz

    submit button not working

    kapil.rajak Level 1

      code:

       

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Panel x="187" y="170" width="331" height="200" layout="absolute" title="Login System">
              <mx:TextInput x="127" y="29" id="username"/>
              <mx:TextInput x="127" y="72" id="password"/>
              <mx:Button x="100" y="119" label="submit" width="117" id="submit" click="login_user.send();"/>
              <mx:Label x="35" y="31" text="Login Name"/>
              <mx:Label x="37" y="74" text="Password"/>
          </mx:Panel>
          <mx:HTTPService
              id="login_user"
              result="checkLogin(event)"
              method="POST"
              url="http://www.vipercreations.com/flex/login.php"
              useProxy="false">
              <mx:request xmlns="">
              <username>{username.text}</username>   
              <password>{password.text}</password>
              </mx:request>
          </mx:HTTPService>
          <mx:Script>
              <![CDATA[
                  private function checkLogin(evt:ResultEvent):void         
                  {
                      if(evt.result.loginsuccess == "yes")
                      {
                          currentState = "Logged In";
                      }
                      if(evt.result.loginsuccess == "no")
                      {
                          mx.controls.Alert.show("Invalid username/password");
                      }       
                  }

       

              ]]>
          </mx:Script>
      </mx:Application>

       

       

      when i run this and entering username ans password, when i submit it by pressing the button, nothing happens, how can i fix this?

        • 1. Re: submit button not working
          kapil.rajak Level 1

          i would like to know also.. how can i submit the same just hitting enter?

          • 2. Re: submit button not working
            Michael Borbor Level 4

            You're missing an import, you need to add this: at the top of the script block

             

            import mx.rpc.events.ResultEvent;

            • 3. Re: submit button not working
              leybniz Level 4

              <mx:TextInput x="127" y="29" id="username" keyDown="onKeyDown(event)"/>
              <mx:TextInput x="127" y="72" id="password" keyDown="onKeyDown(event)"/>

               

              private function onKeyDown(event:KeyboardEvent):void {

                   if (event.keyCode == Keyboard.ENTER)

                    login_user.send();   

              }

              • 5. Re: submit button not working
                kapil.rajak Level 1

                I forgot to add the same import statement, I have added the same. before that it had an error of:    --- the type was not found ot its not compile time constatnt:ResultEvent

                 

                To be precise,its not working even after adding the import statement.

                 

                Even I have entered the codes for working with the ENTER key as suggested here:

                 

                The full code I am posting again; even after pressing down the enter key is not working just like the not working case of the submit button.

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                    <mx:Panel x="187" y="170" width="331" height="200" layout="absolute" title="Login System">
                        <mx:TextInput x="127" y="29" id="username"/>
                        <mx:TextInput x="127" y="72" id="password"  displayAsPassword="true" keyDown="onKeyDown(event)"/>
                        <mx:Button x="100" y="119" label="submit" width="117" id="submit" click="login_user.send();"/>
                        <mx:Label x="35" y="31" text="Login Name"/>
                        <mx:Label x="37" y="74" text="Password"/>
                    </mx:Panel>
                    <mx:HTTPService
                        id="login_user"
                        result="checkLogin(event)"
                        method="POST"
                        url="http://localhost/loginSystem-debug/login.php"
                        useProxy="false">
                        <mx:request xmlns="">
                        <username>{username.text}</username>   
                        <password>{password.text}</password>
                        </mx:request>
                    </mx:HTTPService>
                    <mx:Script>
                        <![CDATA[
                            import mx.rpc.events.ResultEvent;
                           
                            private function onKeyDown(event:KeyboardEvent):void {
                                 if (event.keyCode == Keyboard.ENTER)
                                      login_user.send();  
                            }
                           
                            private function checkLogin(evt:ResultEvent):void
                            {
                                if(evt.result.loginsuccess == "yes")
                                {
                                    currentState = "Logged In";
                                }
                                if(evt.result.loginsuccess == "no")
                                {
                                    mx.controls.Alert.show("Invalid username/password");
                                }       
                            }
                        ]]>
                    </mx:Script>
                </mx:Application>

                • 6. Re: submit button not working
                  kapil.rajak Level 1

                  I have modified the code as you said, its not working, I know the problem lies somewhere in submitting the form.

                   

                  One question I have :- when I write login_user.send() what does it means?

                  Where from it gets the defination for the method send()?

                   

                  I feel its not so big deal though why i am getting stuck.

                  • 7. Re: submit button not working
                    leybniz Level 4

                    send() is a method of HTTPService class.

                    your code works perfectly, the problem is in your backend php script, it's not reachable or doesn't handle POST request correctly.

                    • 8. Re: submit button not working
                      kapil.rajak Level 1

                      The PHP file with the following codes are placed in a folder named loginSystem-debug in the root folder. For me As I am using WAMP the exact path is

                      C:\wamp\www\loginSystem-debug

                       

                      The PHP Code with the name as login.php:

                       

                       

                      <?php

                       

                      define( "DATABASE_SERVER", "localhost" );

                       

                      define( "DATABASE_USERNAME", "user" );

                       

                      define( "DATABASE_PASSWORD", "pass" );

                       

                      define( "DATABASE_NAME", "flex" );

                       

                      //connect to the database

                       

                      $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());

                       

                      //select the database

                       

                      mysql_select_db( DATABASE_NAME );

                       

                      //asign the data passed from Flex to variables

                       

                      $username = mysql_real_escape_string($_POST["username"]);

                       

                      $password = mysql_real_escape_string($_POST["password"]);

                       

                      //Query the database to see if the given username/password combination is valid.

                       

                      $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";

                       

                      $result = mysql_fetch_array(mysql_query($query));

                       

                      //start outputting the XML

                       

                      $output = "<loginsuccess>";

                       

                      //if the query returned true, the output <loginsuccess>yes</loginsuccess> else output <loginsuccess>no</loginsuccess>

                       

                      if(!$result)

                       

                      {

                       

                      $output .= "no";      

                       

                      }else{

                       

                      $output .= "yes";  

                       

                      }

                       

                      $output .= "</loginsuccess>";

                       

                      //output all the XML

                       

                      print ($output);

                       

                      ?>

                      • 9. Re: submit button not working
                        kapil.rajak Level 1

                        It must say that it is not getting the PHP file if such problem is there.

                        Help me plz.

                        • 10. Re: submit button not working
                          leybniz Level 4

                          I've looked into your sources and found no problems, I've commented out all php code related to database access and I were able to get the rsult back,

                          so conclusion is: mxml is ok, php is ok, you should check integration points:

                           

                          1. try to open your service url http://localhost/loginSystem-debug/login.php using regular browser, make sure it responding

                          2. comment out database related code and start with that code "echo '<loginsuccess>no</loginsuccess>';"

                          3. put break point on result handler in mxml, run application under debug mode, investigate obtained results.

                          4. once you are able to get 'no' from the php script, step by step implement more and more logic

                           

                          hope this helps

                           

                          If you feel this message answers your question or helps, please mark it respectively

                          1 person found this helpful