|
|
|
#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();
}
First I tried setting a variable... Code:
set ("submitted", "pestcontrol");
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");
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 |
|
Senior Member
Join Date: Nov 2001
Posts: 871
|
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");
}
//
the onLoad function will happen when your outgoingVars are delivered (instantly usually). gotta go. hope that gets you going. |
|
|
|
|
|
#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");
}
Code:
on (release) {
getURL("javascript:flashFormSubmit();");
}
![]() Tom |
|
|
|
|
|
#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 />"; ?> |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|