views:

43

answers:

2

Complete Flash / AS Noob here. Friend wanted a change in Email address and I'm assisting. I notice at the bottom it posts to a formmail.php file but I was wondering if there was an easier way or perhaps someone could help me understand what exactly it POSTS and how AS handles POST methods so I can rewrite a script. As formmail.php is some script from "Andrew Riley ([email protected])"

function playTier() {

    switch(this.tierContent.tier_txt.text) {
        case "Sinking Ship":
            bullseye_mc.arrow_ani._x = 205; break;
        case "Piggy Bank":
            bullseye_mc.arrow_ani._x = 180; break;
        case "Loose Change":
            bullseye_mc.arrow_ani._x = 155; break;
        default:
            trace("error for arrow posX")
        }   
    bullseye_mc.arrow_ani.play();
    sendEmail();

}

tierContent._alpha = 100;

var recipient = "[email protected]";
var subject = "AP Form";
var nameField:String;
var emailField:String;
var phoneField:String;
var commentsField:String;

//alert format
var alertFormat = new TextFormat();
alertFormat.color = 0xFF0000;
var fields:Array = new Array("name_txt", "email_txt", "phone_txt", "comments_txt");

function alertField():Boolean {
    var checkFailure:Number = 0;
    for (i=0; i<fields.length; i++) {
        if (this[fields[i]].length<1) {
            checkFailure++;
            trace(checkFailure+"-checkFailure");
            this[fields[i]].text = "Required!";
            this[fields[i]].setTextFormat(alertFormat);

        }
    }
    if (checkFailure>0) {
        return false;
    } else {
        return true;
    }

}
function successWindow() {
    this.createTextField("my_txt",1,90,212,300,0);
    this.my_txt.background = true;
    this.my_txt.backgroundColor = 0x00CC00;
    my_txt.multiline = true;
    my_txt.autoSize = true;
    my_txt.wordWrap = true;
    var my_fmt:TextFormat = new TextFormat();
    my_fmt.color = 0xFFFFFF;

    my_fmt.size = 11;
    my_fmt.font = "Verdana";
    my_txt.text = "Thank You. Your information has been submitted.";
    my_txt.setTextFormat(my_fmt);
}

function progressWindow() {
    this.createTextField("progress_txt",1,90,212,300,0);
    this.progress_txt.background = true;
    this.progress_txt.backgroundColor = 0xFD530B;
    progress_txt.multiline = true;
    progress_txt.autoSize = true;
    progress_txt.wordWrap = true;
    var progress_fmt:TextFormat = new TextFormat();
    progress_fmt.color = 0xFFFFFF;

    progress_fmt.size = 11;
    progress_fmt.font = "Verdana";
    progress_txt.text = "Transmitting your information.";
    progress_txt.setTextFormat(progress_fmt);
}

function sendEmail() {
    switch (alertField()) {
        case true :
            progressWindow()
            trace("break!");
            var result_lv:LoadVars = new LoadVars();

            result_lv.onLoad = function(success:Boolean) {
                if (success) {
                    trace("Form sent!");
                    successWindow();
                } else {
                    trace("Error in sending");

                }
            };
            var send_lv:LoadVars = new LoadVars();
            send_lv.recipient = "[email protected]";
            send_lv.subject = "AP Form";
            send_lv.sort = "order:name,company,email,phone,question1,question2,question3,question4,question5,question6,question7,question8"
            send_lv.name = this._parent.q9.name_txt.text;
            send_lv.company = this._parent.q9.company_txt.text;
            send_lv.email = this._parent.q9.email_txt.text;
            send_lv.phone = this._parent.q9.phone_txt.text;

            send_lv.question1 = this._parent._parent.qArray[0];
            send_lv.question2 = this._parent._parent.qArray[1];
            send_lv.question3 = this._parent._parent.qArray[2];
            send_lv.question4 = this._parent._parent.qArray[3];
            send_lv.question5 = this._parent._parent.qArray[4];
            send_lv.question6 = this._parent._parent.qArray[5];
            send_lv.question7 = this._parent._parent.qArray[6];
            send_lv.question8 = this._parent._parent.qArray[7];


            send_lv.sendAndLoad("formmail.php",result_lv,"POST");




                if(lvBytesLoaded < lvBytesTotal) {
                     progressWindow()
                    }


            break;
        case false :
            trace("Error missing fields- nothing sent");
            break;
        default :
            trace("Something bad happen");
            break;
    }
};
+1  A: 

Hi, Austin.

If you could post the exact change that your friend wants to make, it would be helpful in answering your question. It sounds like you just need to change the email address, though.


A short answer to your question:

There is some confusion built into this code - there are variables defined and populated that you would expect to be what is sent to the server. BUT, these variables are not referred to later on, when the information is being packaged up in the send_lv object to be sent up to the server.

If you need to change the email address that the email is going to, change send_lv.recipient = "[email protected]"; to send_lv.recipient = "[email protected]", or whatever.

You could modify to code to make use of the recipient var that is defined near the top of the code, like so:

send_lv.recipient = recipient;

If you do this, then you need to change var recipient = "[email protected]"; to var recipient = "[email protected]";.


A longer answer to your question:

It's been a pretty long time since I've worked with AS2, but what the code you posted is doing, in general, is gathering the elements of an email and then sending those elements to a PHP script. The PHP script will use the elements it receives to construct and then send an email. In this case, the email will go to [email protected], with a subject line of AP Form. My guess is that the remaining elements - name, company, email, phone, and the list of questions (or question answers, more likely) will be used to construct the body of the email.

The send_lv object represents the information that will be sent to the server. It is also the means of sending the information to the server (send_lv.sendAndLoad()). The sendAndLoad method sends information to the server and requests a response, which in this case triggers the successWindow function. In between the time that the information is sent and the time a result is received from the server, a progress window is displayed.

You can read up a bit on this method on the LiveDocs documentation. It's pretty informative, and explains the difference between the sendAndLoad, send, and load methods.

Hope that helps.

Ross Henderson
Thank you very much for the information. I've tried to change the email address but it didn't send to the email I changed it to, which lead me to believe that the formmail.php script was broken and to just write a new script.Thank you, I will look into LiveDocs though.
Austin
You bet. Do you have access to the formmail.php script? Sounds like it might be using a hardcoded value for the email address.
Ross Henderson
+1  A: 

perhaps someone could help me understand what exactly it POSTS

It posts all variables of the send_lv object (name, company, email, etc.) concatenated as urlencoded string.

If you need a variable in the backend script, just define it on the send_lv object and access it as post variable in the php script.

send_lv.dummy = "my new var"; //frontend

$dummy = filter_input('dummy', INPUT_POST); // in php script
Thomas Schuster
so then in the php file all I'd have to do was $dummy = $_GET['dummy']; and it'll append properly?
Austin
If you set a property on the send_lv object you can access that property as a POST variable in the php script as described above. $_POST['dummy'] would do the job but I recommend you to look at http://www.php.net/manual/en/filter.filters.sanitize.php for security reasons.You could sanitize an email by using "$dummy = filter_input('dummy', INPUT_POST, FILTER_SANITIZE_EMAIL); " (filter functions require PHP 5 >= 5.2.0).
Thomas Schuster