9 Replies Latest reply on May 29, 2007 7:38 PM by dkerr

    Basic Form Submit via RemoteObject

    dkerr Level 1
      Ben Forta graceously help me with the overall process and said this is what I need.

      1) Create a ColdFusion CFC method which accepts a record to insert,
      either a struct with properties or just a list of arguments.

      DONE

      2) Define a <mx:RemoteObject> connection to the CFC.

      DONE

      3) Create your form in Flex. The click event on the form button
      calls an AS function.

      FORM LAYOUT DONE, but not AS.

      4) That AS function does any validation, and then calls cfcObj.method
      () passing it an equivalent AS class or the values comma delimited.


      What I still need help with is the AS to tie the onclick in the
      button, to an AS function, then passing the form data to the
      remoteobject.

      Probably pretty easy AS, but I'm just trying to learn AS.
      Conceptually, the process is clear, but I need to see a generic
      example of the syntax. Here is portions of the code so far:

      <mx:Script>
      function sendFormdata(){
      ???????
      }
      </mx:Script>

      <mx:RemoteObject
      id="cfdataInsert" showBusyCursor="true"
      destination="ColdFusion"
      source="da8.Constellation.entries">
      <mx:method name="createEntry" result="createEntry_result(event)" />
      ????
      </mx:RemoteObject>


      <mx:FormItem label="Name" id="FI_Name" required="true"
      horizontalAlign="left">
      <mx:TextInput id="Name" editable="true" enabled="true" width="300"/>
      </mx:FormItem>
      <mx:FormItem label="email" id="FI_email" required="true">
      <mx:TextInput id="Form_email" width="300"/>
      </mx:FormItem>
      <mx:FormItem id="FI_BTN_send">
      <mx:Button label="Send" id="BTN_Send" click="sendFormdata()"
      enabled="true" labelPlacement="right"/>
      </mx:FormItem>

      I'd appreciate any help pulling these three parts together.

      Thanks,
      Don
        • 1. Re: Basic Form Submit via RemoteObject
          Jighead52 Level 1
          Don,

          Try this

          First a simple CFC function that inserts the data.

          <cfcomponent>
          <cffunction name="addData" access="remote" output="false" hint="I insert data" returntype="void">
          <cfargument name="user" type="struct" required="true" />
          <!--- you can manipulate the "arguments.user" struct here if needed prior to inserting. --->

          <cfquery datasource="mydsn">
          insert into myTable
          (name, email)
          values
          ('#name#', '#email#')
          </cfquery>
          </cffunction>


          And the AS function.

          <mx:Script>
          <![CDATA[
          private function sendFormdata():void {
          var myobj:Object = new Object();
          myobj.name = nameInput.text;
          myobj.email = emailInput.text;

          /* "cfdataInsert" is the id of your remoteObject and
          "adddata" is the function in your cfc that will insert the data
          "user" is the cfargument name ... so call the cfc function and
          bind the form object (myobj) inside the function call.
          This is similar to passing an argument collection via
          a coldfusion function
          */
          cfdataInsert.addData({user:myobj})
          }
          ]]>
          </mx:Script>

          <mx:RemoteObject
          id="cfdataInsert" showBusyCursor="true"
          destination="ColdFusion"
          source="da8.Constellation.entries">
          <mx:method name="createEntry" result="createEntry_result(event)" />

          ????
          </mx:RemoteObject>


          <mx:FormItem label="Name" id="FI_Name" required="true"
          horizontalAlign="left">
          <mx:TextInput id="Name" editable="true" enabled="true" width="300"/>
          </mx:FormItem>
          <mx:FormItem label="email" id="FI_email" required="true">
          <mx:TextInput id="Form_email" width="300"/>
          </mx:FormItem>
          <mx:FormItem id="FI_BTN_send">
          <mx:Button label="Send" id="BTN_Send" click="sendFormdata()"
          enabled="true" labelPlacement="right"/>
          </mx:FormItem>


          Hope this helps.

          Gerd
          • 2. Re: Basic Form Submit via RemoteObject
            dkerr Level 1
            Thank you Gerd. This makes sense. I'll give it a try.

            I'm amazed. I've search all adobe docs, many sites/blogs, and even exchanged emails with key Adobe engineers....and I'm amazed how hard it is to find the basics!! So, I really appreciate the help.

            If it works, I'll post my code as soon as i can get to it so others can benefit.

            Don
            • 3. Re: Basic Form Submit via RemoteObject
              dkerr Level 1
              Gerd,

              I keep getting an error like this

              [RPC Fault faultString="Variable myname is undefined." faultCode="Server.Processing" faultDetail=""]
              at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::faultHandler()
              at mx.rpc::Responder/fault()
              at mx.rpc::AsyncRequest/fault()
              at ::NetConnectionMessageResponder/NetConnectionChannel.as$37:NetConnectionMessageResponder: :statusHandler()
              at mx.messaging::MessageResponder/status()


              Here is the AS
              <mx:Script>
              <![CDATA[
              private function sendFormdata():void {
              var myobj:Object = new Object();
              myobj.myname = myname.text;
              myobj.myemail = myemail.text;
              myobj.myentry = myentry.text;

              cfdataInsert.addData({user:myobj})
              }
              ]]>
              </mx:Script>

              Here is the part of my form where myname,myemail,myentry are defined. I must not have the formitem or textinputs correct or something?

              <mx:VBox>
              <mx:FormItem label="Name" id="finame" required="true" horizontalAlign="left">
              <mx:TextInput name="myname" id="myname" editable="true" enabled="true" width="300"/>
              </mx:FormItem>
              <mx:FormItem label="email" id="fiemail" required="true">
              <mx:TextInput name="myemail" id="myemail" width="300"/>
              </mx:FormItem>
              <mx:FormItem label="Subject" id="entry" required="true">
              <mx:TextInput name="myentry" id="myentry" width="300"/>
              </mx:FormItem>
              </mx:VBox>

              It is interesting: when I had a name and email cookie defined and used name and email in my form, the insert/CFC worked great for name and email, but entry was undefined error. Then I put "my" in front of all three and now all three are undefined?

              I think the mxml form part is not correct, since I know the AS, Remoteobject, and CFC work fine. Question is what is wrong with my variables?

              I'd appreciate the help...getting close!! :)

              Don
              • 4. Re: Basic Form Submit via RemoteObject
                Jighead52 Level 1
                Error message says... "the variable myname is not defined" .. looks like it's not passing the value for the myname textbox to the function also try removing the name attributes from the textboxes. Looks like they are duplicating the id's.
                • 5. Re: Basic Form Submit via RemoteObject
                  dkerr Level 1
                  I removed the name and just have id, but I still get the same undefined error.

                  Does the id of the formitem, not the textinput, get passed to the function?

                  <mx:FormItem label="Name" id="finame" required="true" horizontalAlign="left">
                  <mx:TextInput id="myname" editable="true" enabled="true" width="300"/>
                  </mx:FormItem>
                  <mx:FormItem label="email" id="fiemail" required="true">
                  <mx:TextInput id="myemail" width="300"/>
                  </mx:FormItem>
                  <mx:FormItem label="Subject" id="entry" required="true">
                  <mx:TextInput id="myentry" width="300"/>
                  </mx:FormItem>
                  • 6. Re: Basic Form Submit via RemoteObject
                    dkerr Level 1
                    problem was in my cfc. had to change #myname# to #user.myname# , etc. Then the variable was defined and submit worked.

                    Thanks for the help!
                    Don
                    • 7. Re: Basic Form Submit via RemoteObject
                      Jighead52 Level 1
                      Hi Don,

                      Great, glad you got it worked out. I was traveling and unable to respond to your last post. I was going to put up a simpler example this morning but no need now.

                      Gerd
                      • 8. Re: Basic Form Submit via RemoteObject
                        GeorgeWS Level 1
                        I am trying out the examples and I get this error when I clean it:
                        Call to possibly undefined methed createEntry_result.

                        I do not see that method anywhere in the samples, what should it be?
                        • 9. Re: Basic Form Submit via RemoteObject
                          dkerr Level 1
                          ignore the call to createntry (carry over from just a separate example). All you need is sendFormdata() to call the adddata function.

                          Don