A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Help with strings. PHP+flash contact form.

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    7

    Help with strings. PHP+flash contact form.

    Hello.

    I'm working in a flash contact form which communicates with PHP in order to send the information in the input fields to an e-mail address. The ActionScript code has already been nailed down; it works perfectly in flash.

    However, here lies my problem. I was working with a simple flash form tutorial found HERE and it uses a very simple PHP code to obtain the variables sent from the flash from. I had my AS code changed and it looks like this:
    Code:
    stop();
    
    tel_box.restrict = "\\ 0-9\\-\\()\\+";
    
    name_box.tabIndex = 1;
    email_box.tabIndex = 2;
    tel_box.tabIndex = 3;
    subject_box.tabIndex = 4;
    message_box.tabIndex = 5;
    
    System.useCodepage = true;
    my_vars = new LoadVars();
    
    send_btn.onRelease = function() {
        // added this boolean var
        var doSend = true;
       
        my_vars.sender = email_box.text;
        my_vars.subject = subject_box.text;
        my_vars.message = message_box.text;
        my_vars.phone = tel_box.text;
        my_vars.name = name_box.text;
       
        //  changed != to == and the ands to ors
        if (my_vars.sender == "" or my_vars.subject == "" or my_vars.message == "" or my_vars.name == "" or my_vars.phone == "") {
            doSend = false;
        }
       
        //  added this - makes sure sender is longer than 3 characters
        if (my_vars.sender.length < 3){
            doSend = false;
        }
       
        //  added this - checks sender for @ symbol
        if (my_vars.sender.indexOf("@") == (-1)){
            doSend = false;
        }
       
        //  added this - checks sender for @ symbol
        if (my_vars.sender.indexOf(".") == (-1)){
            doSend = false;
        }
       
        //  added this - makes sure message is longer than 10 characters
        if (my_vars.message.length < 10){
            doSend = false;
        }
       
        //  added this - makes sure Subject is longer than 3 characters
        if (my_vars.subject.length < 3){
            doSend = false;
        }
       
        //  added this - makes sure Name is longer than 3 characters
        if (my_vars.name.length < 3){
            doSend = false;
        }
       
        //  added this - makes sure Phone is longer than 6 characters       
        if (my_vars.phone.length < 6){
            doSend = false;
        }
       
        //  either send or show error
        if (doSend) {
            my_vars.sendAndLoad("contact.php", my_vars, "POST");
            gotoAndStop(2);
        } else {
            error_clip.gotoAndPlay(2);
        }
    };
    
    
    
    my_vars.onLoad = function() {
        gotoAndStop(3);
    };
    
    email_box.onSetFocus = subject_box.onSetFocus=message_box.onSetFocus=name_box.onSetFocus=tel_box.onSetFocus=function () {
        if (error_clip._currentframe != 1) {
            error_clip.gotoAndPlay(6);
        }
    };

    So I changed the PHP file thinking it would behave exactly the same as before. It looks like this:

    Code:
    <?php
    // read the variables form the string, (this is not needed with some servers).
    $name = $_REQUEST["name"];
    $sender = $_REQUEST["sender"];
    $phone = $_REQUEST["phone"];
    $subject = $_REQUEST["subject"];
    $message = $_REQUEST["message"];
    
    // include sender IP in the message.
    $full_message = $_SERVER['REMOTE_ADDR'] . "\n\n" . $message;
    $message= $full_message;
    
    // remove the backslashes that normally appears when entering " or '
    $message = stripslashes($message);
    $subject = stripslashes($subject);
    $sender = stripslashes($sender);
    $phone = stripslashes($phone);
    $name = stripslashes($name);
    
    // add a prefix in the subject line so that you know the email was sent by online form
    $subject = "Contact form: ". $subject;
    
    // send the email, make sure you replace email@yourserver.com with your email address
    if(isset($message) and isset($subject) and isset($sender) and isset($name) and isset ($phone){
        mail("bluelinesmx@gmail.com", $name, $phone, $subject, $message, "From: $sender");
    }
    ?>
    In a few words: PHP isn't reading the variables from the strings in flash. I assume the problem lies within the PHP coding. Can anyone help me with this?

    Thanks in advance.
    J.

  2. #2
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Try using the PHP global array $_POST["name"...etc] instead of $_REQUEST. Depending on the configuration of the php.ini file on your server, $_REQUEST might not be holding the inbound variables.

    Also, just to confirm that your server is receiving the data from Flash, you should do a tracer like
    PHP Code:
    $test fopen("test.txt","w");
    fwrite($test,"hello"); 
    at the top of your php code (make sure there's a 777 mod on the directory so PHP can write a file there) ...then at least you can be sure that this isn't related to Flash requesting a missing file or anything like that.

  3. #3
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    near the end of your code

    if(isset(...) and isset(...)) {

    be sure to have two ))

    Musicman

  4. #4
    Junior Member
    Join Date
    Apr 2010
    Posts
    7
    Quote Originally Posted by joshstrike View Post
    Try using the PHP global array $_POST["name"...etc] instead of $_REQUEST. Depending on the configuration of the php.ini file on your server, $_REQUEST might not be holding the inbound variables.

    Also, just to confirm that your server is receiving the data from Flash, you should do a tracer like
    PHP Code:
    $test fopen("test.txt","w");
    fwrite($test,"hello"); 
    at the top of your php code (make sure there's a 777 mod on the directory so PHP can write a file there) ...then at least you can be sure that this isn't related to Flash requesting a missing file or anything like that.
    Changed $_REQUEST to $_POST and still nothing.
    Tracer works fine.

    My guess is: maybe the strings are the problem. Any ideas?

  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    7
    Finally, I've got the code working.

    I really have no clue where the problem lies. I found this thread here in flashkit (http://board.flashkit.com/board/showthread.php?t=812624) and this one DOES work.

    I tried removing the stripslashes but nothing. The isset didn't make a change either.

    Anyway, thanks for your help guys

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