Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with send(), sendAndLoad() or LoadVars please?

Status
Not open for further replies.

DougieMcN

Technical User
Sep 16, 2007
13
Hi, I have a form set up in flash pointing to a PHP script on my webspace.

I checked the PHP script and when viewed in a browser it returns the parameters OK so I presume it is working.

My problem is the variables captured by user input are not being sent to me.

Please can anyone check my actionscript below for errors.

I have tried send() and sendAndLoad() so I feel I may have an issue with my LoadVars.

Thanks in advance.

stop();

var fullName:TextField;
var fullAddress:TextField;
var postcode:TextField;
var telNumber:TextField;
var emailAddress:TextField;

fullName.restrict = "A-Za-zÁáÉéêíÍãõç ";
fullName.maxChars = 40;

fullAddress.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
fullAddress.maxChars = 90;

postcode.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
postcode.maxChars = 10;

telNumber.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
telNumber.maxChars = 20;

emailAddress.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
emailAddress.maxChars = 50;

function sendEmail(fullName, fullAddress, postcode, telNumber, emailAddress)
{
var myData:LoadVars = new LoadVars();
myData.fullName = fullName.text;
myData.fullAddress = fullAddress.text;
myData.postcode = postcode.text;
myData.telNumber = telNumber.text;
myData.emailAddress = emailAddress.text;
}
this.submitButton.onRelease = function()
{
if (fullName.text == "" || fullAddress.text == "" || postcode.text == "" || telNumber.text == "")
{
gotoAndStop("error");
}

else

{
sendEmail();
gotoAndStop("correct");
}

myData.send(" "POST");
};
 
[tt]sendEmail();[/tt]

...should be...

[tt]this._parent.sendEmail();[/tt]

because [tt]sendEmail[/tt] is defined in your main timeline, which is [tt]_parent[/tt] of your [tt]submitButton[/tt].

The same applies to [tt]myData[/tt].

Kenneth Kawamoto
 
Hi, thanks for your reply.

I have changed my code as per the new version below but am still not receiving the user input from the form.

Can you please look at it again for me to see if I have changed it as per your recommendation.

Thanks again.

Code:
stop();

var fullName:TextField;
var fullAddress:TextField;
var postcode:TextField;
var telNumber:TextField;
var emailAddress:TextField;

fullName.restrict = "A-Za-zÁáÉéêíÍãõç ";
fullName.maxChars = 40;

fullAddress.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
fullAddress.maxChars = 90;

postcode.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
postcode.maxChars = 10;

telNumber.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
telNumber.maxChars = 20;

emailAddress.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
emailAddress.maxChars = 50;

function sendEmail(fullName, fullAddress, postcode, telNumber, emailAddress)
{
var myData:LoadVars = new LoadVars();
myData.fullName = fullName.text;
myData.fullAddress = fullAddress.text;
myData.postcode = postcode.text;
myData.telNumber = telNumber.text;
myData.emailAddress = emailAddress.text;
}
this.submitButton.onRelease = function()
{
if (fullName.text == "" || fullAddress.text == "" || postcode.text == "" || telNumber.text == "")
{
gotoAndStop("error");
}

else

{
this._parent.sendEmail();
gotoAndStop("correct");
}

this._parent.myData.send("[URL unfurl="true"]http://www.mywebsite.co.uk/iopost.php",[/URL] "POST");
};
 
Thanks again.

Do you mean I should declare it as a variable at the beginning of the code or I should define it as a function or LoadVars in it's own right.

If you can possibly give me some sort of example which applies to the code I previously supplied to help point me in the right direction I would appreciate it.

Thanks.
 
Hi.

I have tried changing my code as per below so 'myData:LoadVars' is scoped outside of the 'sendEmail' function. I have tried uploading but still am not recieving the user input data.(It is now at the top of the code along with the other variables)

Can you let me know if this is what you recommended.

Thanks again.

Code:
stop();

var fullName:TextField;
var fullAddress:TextField;
var postcode:TextField;
var telNumber:TextField;
var emailAddress:TextField;
var myData:LoadVars = new LoadVars();

fullName.restrict = "A-Za-zÁáÉéêíÍãõç ";
fullName.maxChars = 40;

fullAddress.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
fullAddress.maxChars = 90;

postcode.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
postcode.maxChars = 10;

telNumber.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
telNumber.maxChars = 20;

emailAddress.restrict = "0-9A-Za-zÁáÉéêíÍãõç!?.+\- ";
emailAddress.maxChars = 50;

function sendEmail(fullName, fullAddress, postcode, telNumber, emailAddress)
{
myData.fullName = fullName.text;
myData.fullAddress = fullAddress.text;
myData.postcode = postcode.text;
myData.telNumber = telNumber.text;
myData.emailAddress = emailAddress.text;
}
this.submitButton.onRelease = function()
{
if (fullName.text == "" || fullAddress.text == "" || postcode.text == "" || telNumber.text == "")
{
gotoAndStop("error");
}

else

{
this._parent.sendEmail();
gotoAndStop("correct");
}

this._parent.myData.send("[URL unfurl="true"]http://www.mywebsite.co.uk/iopost.php",[/URL] "POST");
};
 
Code:
this.submitButton.onRelease = function():Void  {
	if (this._parent.fullName.text == "" || this._parent.fullAddress.text == "" || this._parent.postcode.text == "" || this._parent.telNumber.text == "") {
		gotoAndStop("error");
	} else {
		this._parent.sendEmail();
		this._parent.myData.send("[URL unfurl="true"]http://www.mywebsite.co.uk/iopost.php","POST");[/URL]
		gotoAndStop("correct");
	}
};



Kenneth Kawamoto
 
Hi, thanks so much for your help Kenneth.

That did the job exactly as you suggested.

May I ask for one final piece of advice if possible.

When I click the submit button on my form it sends the data but also opens up a blank HTML page as well. I wouldn't mind this at all but it displays the address to the PHP file in the HTML address bar.

Is it possible to preferably get rid of the HTML page (I've tried sendAndLoad but the data won't send using this) or at least can you recommend how to cloak the address bar for security.

If not thanks anyway for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top