A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Help with LoadVars()/sendAndLoad() in my form

Hybrid View

  1. #1
    Confounded Flash User
    Join Date
    Apr 2001
    Location
    Chicago
    Posts
    39

    Help with LoadVars()/sendAndLoad() in my form

    Hi there,

    I've been trying to figure this out and the documentation is really confusing, at least to me. First, I have a basic HTML form that I am submitting with a flash button. To do that I am doing this:

    Code:
    (actionscript on button)
    
    on (release) {
    	getURL("javascript:flashFormSubmit();");
    }
    
    (javascript in page)
    function flashFormSubmit()
    {
    	var myForm = document.forms[0];
    	myForm.submit();
    }
    That has tested to work fine. Now, the next thing I need to do is tell the server which button has been pressed, since there are multiple submit buttons. This is where things are confusing. How can I send some kind of variable to the server on post along with the form submission?

    First I tried setting a variable...

    Code:
    set ("submitted", "pestcontrol");
    But couldn't figure out how to send it. Then I found this code"

    Code:
    var ldata = new LoadVars();
    ldata.dataToSend = "pestcontrol";
    ldata.onLoad = function(success)
    {
         if(success){
              trace(this.dataReceived);
         } else {
              trace("error");
         }
    }
    ldata.sendAndLoad("self2.html?submitted=pestcontrol", ldata, "POST");
    self2.html is the page I am posting to for my testing. Adding this has no effect on my page. I tried to put it after the on(release) and that did nothing either. A few things are confusing, first of all the method is POST here but the URL shown is a GET string.

    Secondly, since I am submitting the form with javascript, I don't see how anything outside the HTML can be sent. How can I insert my variable to get sent along with the post?

    Sorry this is convoluted but I am fairly confused - all I want to do is send a button name that can be read in the POST.

    Thanks

    Tom

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    you're close. you want to make two loadVars - outgoingVars and incomingVars (those are names i made up). then, you put anything you want to send out in outgoingVars:

    outgoingVars.buttonPressed = "pestcontrol";

    here's an example of send and load - sending vars to serverside scripting (php, asp, cf) just like an html form would do with a form submit.

    Code:
    //
    function doSend(){
    	outgoingVars.sendAndLoad("flashForm.aspx",incomingVars,"GET");
    	gotoAndPlay("submitted");
    	}// function
    //
    //
    incomingVars.onLoad = function(success) {
    	gotoAndPlay("received");
    }
    //
    here outgoingVars are sent to an asp page that handles form submissions called "flashform.aspx". that flashform.aspx will receive everything i put in outgoingVars. you could put your whole form in flash with what you know.

    the onLoad function will happen when your outgoingVars are delivered (instantly usually).

    gotta go. hope that gets you going.

  3. #3
    Confounded Flash User
    Join Date
    Apr 2001
    Location
    Chicago
    Posts
    39
    Right now I'm only using a simple HTML page, no server side scripting. I'm just picking off the GET vars of the URL with JavaScript. In any event, I added the code Moot supplied (thanks) but nothing changed. My script does not see the "buttonPressed" var.

    So right now I have this:

    Code:
    outgoingVars.buttonPressed = "pestcontrol";
    
    function doSend(){
    	outgoingVars.sendAndLoad("self2.html",incomingVars,"GET");
    // wouldn't the above be ("self2.html",outgoingVars,"GET")? doesn't work either way
    	gotoAndPlay("submitted");
    	}
    
    incomingVars.onLoad = function(success) {
    	gotoAndPlay("received");
    }
    with this still on the button
    Code:
    on (release) {
    	getURL("javascript:flashFormSubmit();");
    }
    I'm confused about the gotoAndPlay() method here - my movie is nothing more than a button - why would it want to go anywhere? Also, my movie need not receive anything back at all - I just need to make the "pestcontrol" variable available to the form, actually in post form eventually, but get will work for now. Sorry about being dense, but I don't understand the process of how Flash sends over stuff so I can't seem to wrap my head around this

    Tom

  4. #4
    Confounded Flash User
    Join Date
    Apr 2001
    Location
    Chicago
    Posts
    39
    Ok, instead of using the old HTML page, I added a PHP page to process the POST to be more accurate and see if the server is getting anything, using this:

    Code:
    <?php
    $txt = $_POST['textfield'];
    $btn = $_POST['buttonPressed'];
    
    print "t: $txt<br />";
    print "b: $btn<br />";
    ?>
    $btn is empty, so outgoingVars.buttonPressed is not getting through...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center