View Full Version : get variables from mc (what's wrong here?)
myBad.script
07-09-2004, 01:33 PM
I have a simple contact form called into a movieclip on the main timeline. The movie clip is mc_mailForm (which loads "mailform_perl.swf"). There's an input textfield, instance "tf_sender" with the Variable "senderName."
Shouldn't this on(release) at least trace the variable (or an error) for me?
formData = new LoadVars();
formData.senderName = _root.mc_mailForm.tf_sender;
formData.onLoad = function(success) {
if(success) {
trace(senderName);
}else{
trace("Oops. You goofed.");}
}
The form worked perfectly as a standalone movie with all the variables local, but I can't figure out how to get the variables out of the clip when it's inside the main timeline. I've tried every combination I can think of, but still. No joy.
CyanBlue
07-09-2004, 01:58 PM
What about this???
trace(this.senderName);
myBad.script
07-09-2004, 02:09 PM
No joy. You'd think I'd at least get the error.
myBad.script
07-09-2004, 02:20 PM
There are a series of if...else statements ahead of the LoadVars. What's not executing is the final } else { statement. Here's the function in my script:
function perlSendMail() {
if (_root.mc_mailForm.tf_sender.length<1) {
_root.mc_mailForm.emailStatus = "Please Enter your name before Sending";
trace("empty fromSender field detected");
} else if (_root.mc_mailForm.tf_eMail.length<1) {
_root.mc_mailForm.emailStatus = "Please enter a valid E-mail address";
trace("empty fromEmail field detected");
} else if (_root.mc_mailForm.tf_message.length<1) {
_root.mc_mailForm.emailStatus = "Please enter some text in your message";
trace("empty message field detected");
} else {
trace("formData = new LoadVars() has been invoked.");
formData = new LoadVars();
formData.senderName = _root.mc_mailForm.tf_sender;
formData.onLoad = function(success) {
if(success) {
trace(this.senderName);
}else{
trace("Oops. You goofed.");}
}
CyanBlue
07-09-2004, 02:22 PM
Well... Where is your sendAndLoad() call???
Do you even get this trace out???
trace("this = " + unescape(this));
trace("this.senderName = " + this.senderName);
myBad.script
07-09-2004, 02:25 PM
I was going to add the sendAndLoad once I got the script past the else statement.
CyanBlue
07-09-2004, 02:47 PM
Uh, what??? You get nothing if you not use sendAndLoad() function...
onLoad handler gets fired only AFTER you receive something from the external source...
myBad.script
07-09-2004, 05:35 PM
Making some progress. I now get traces from the IF statements....but the variable traces out as undefined.
Here's the code:
formData = new LoadVars();
this.trace("new LoadVars() executed.");
formData.senderName = _root.mc_mailForm.senderName;
this.trace(senderName)
formData.sendAndLoad("http://www.lmbsg.com/cgi-bin/lmbsgMailPerl.cgi","0","POST");
formData.onLoad = function(success) {
if(success) {
this.trace("form data connection made");
}else{
this.trace("Oops. You goofed.");
}
}
}
}
Here are the traceouts:
new LoadVars() executed.
undefined
When run from the server, it didn't post, but as there's no variable I'm not surprised.
CyanBlue
07-09-2004, 05:43 PM
Try this...
formData = new LoadVars();
trace("new LoadVars() executed.");
formData.senderName = _root.mc_mailForm.senderName;
trace(formData.senderName);
formData.onLoad = function(success)
{
if (success)
{
trace("form data connection made");
trace("Data = " + unescape(this));
}
else
{
trace("Oops. You goofed.");
}
}
formData.sendAndLoad("http://www.lmbsg.com/cgi-bin/lmbsgMailPerl.cgi", formData, "POST");
You should really go to the tutorials page and read the LoadVars tutorials and the path tutorials...
myBad.script
07-09-2004, 06:09 PM
CyanBlue, that notched it. The traceouts all required "this.trace" to work....email is now flowing. The missing link to the sendAndLoad() method was to target the loadVars() object (formData). So now the only thing to make functional is the server feedback message from the perlscript.cgi file that's written thus:
print "Content-type: text/html\n\n";
print "_root.mc_mailForm.emailStatus=Complete - Your message has been received";
There's also a matching failure message; it reported back with the old loadVariablesNum() approach. I think I'll just fiddle with it.
CyanBlue
07-09-2004, 06:18 PM
Uh... It'd be great if you could call me CyanBlue not Cyan... :D
Glad that helped... But you should get rid of the 'this.' in front of the 'trace()' function calls... That, this.trace(), works, but that is not the right way of doing it, I think... :)
There's also a matching failure message; it reported back with the old loadVariablesNum() approach
I don't know what you are talking about on that because you didn't provide any information on that, but one thing that is very clear to me is that you should not call the same Perl script via loadVariablesNum() function because that will call the same Perl script twice...
myBad.script
07-09-2004, 06:36 PM
Dropped the loadVariablesNum completely to learn the new LoadVars technique, so I'm on board with you. Now I just have to get the feedback message that's embedded in the perlscript (code below), or generate it as part of the onLoad(success) function.
perlscript code:
print "Content-type: text/html\n\n";
print "_root.mc_mailForm.emailStatus=Complete - Your message has been received";
CyanBlue
07-09-2004, 06:38 PM
Um... Just curious... Is there question in your last post or are you just telling me the process that you have to go from here??? :)
myBad.script
07-09-2004, 07:32 PM
Not sure myself. :D
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.