Friday, November 21, 2008

Easy way to handle form in Flex 3

The easiest way I've found to post a form is to use the HTTPService tag with a method="post".

Here's the HTTPService tag (and some email validation as well) Note the code embedding tags I'm using mess this up. The EmailValidator should be closed before the HTTPService call.







{fullName.text}


{email.text}


{comment.text}







Here's the form. Again the embedder adds three closing formitem tags that shouldn't be there.























And here's the script. This validates that the email address isn't empty and pops up an alert message saying the form has been submitted. Then it clears out the fields.





import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;

public function resultHandler(event:ResultEvent):void
{

if (email.text == "")
{
mx.controls.Alert.show("Please enter an email address")
} else
{
mx.controls.Alert.show("Thank you. Your information has been sent.");
fullName.text = "";
email.text = "";
comment.text = "";
}
}
]]>


No comments: