A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: email form as2 code to as3

  1. #1
    Junior Member
    Join Date
    Feb 2006
    Posts
    24

    email form as2 code to as3

    Hi all,
    i have this email form that works with as2 but i need it to work with as3. If someone is bothered please help.

    AS2 code:
    email_txt.restrict = "a-z_.@0-9";
    email_txt.maxChars = 40;

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

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

    comments_txt.onSetFocus = function()
    {
    status_txt.text = '';
    }
    email_txt.onSetFocus = name_txt.onSetFocus = phone_txt.onSetFocus = comments_txt.onSetFocus;

    status_txt.text = 'All fields required';


    submit_btn.onRelease = function()
    {
    var email = email_txt.text;
    var namee = name_txt.text;
    var comment = comment_txt.text;

    // are all the fields filled?
    if (namee == '') {
    status_txt.text = "You need to fill in your Name.";
    return;
    }

    if (email == '') {
    status_txt.text = "You need to fill in your E-mail.";
    return;
    }
    // you should also validate the email address

    if (comment == '') {
    status_txt.text = "Please, don't forget your Comment!";
    return;
    }

    // yes, all fields filled
    sendEmail(name, email, comment);

    // sending data...
    status_txt.text = "Processing mail form...";

    // prevent submitting again by disabling the button
    this.enabled = false;
    };


    function sendEmail(name, email, comment)
    {
    var myData = new LoadVars();

    myData.name = name;
    myData.email = email;
    myData.comment = comment;

    myData.onLoad = function(ok) {
    if (ok) {
    status_txt.text = this.message;
    } else {
    status_txt.text = "There was an error. Try again later.";
    }
    submit_btn.enabled = true;
    };

    myData.sendAndLoad('contactform.php', myData, 'POST');
    }

  2. #2
    Junior Member
    Join Date
    Feb 2006
    Posts
    24
    namee should be name btw

  3. #3
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    PHP Code:
    email_txt.restrict "a-z_.@0-9";
    email_txt.maxChars 40;

    name_txt.restrict "A-Za-zÁáÉéê*Íãõç ";
    name_txt.maxChars 40;

    comments_txt.restrict "0-9A-Za-zÁáÉéê*Íãõç!?.+\- ";
    comments_txt.maxChars 200;

    function 
    clearText(event:Event){
        
    event.currentTarget.text "";
    };
    email_txt.addEventListener("focusIn",clearText);
    name_txt.addEventListener("focusIn",clearText);
    phone_txt.addEventListener("focusIn",clearText);
    comments_txt.addEventListener("focusIn",clearText);

    status_txt.text 'All fields required';

    function 
    submitForm(event:Event){
        if(
    name_txt.text == ""){
            
    status_txt.text "You need to fill in your Name.";
            return 
    false;
        }
        if(
    email_txt.text == ""){
            
    status_txt.text "You need to fill in your E-mail.";
            return 
    false;
        }
        if(
    comments_txt.text == ""){
            
    status_txt.text "Please, don't forget your Comment!";
            return 
    false;
        };
        var 
    variables:URLVariables = new URLVariables();
        
    variables.sender name_txt.text;
        
    variables.email email_txt.text;
        
    variables.comment comment_txt.text;
        var 
    request:URLRequest = new URLRequest();
        
    request.url "contactform.php";
        
    request.method URLRequestMethod.POST;
        
    request.data variables;
        var 
    loader:URLLoader = new URLLoader();
        
    loader.load(request);
    };

    submit_btn.addEventListener("click",submitForm); 

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