Hi all. I have been working on a action script and finally got it working. I am totally lost of how to write my PHP email codes for when the person press submit all the information they fill in is sent to me via email could someone help me please. I found tons of example off the internet to write a basic one but nothing close to what I have. Or better said none with check boxes buttons. Could someone please help me. Below is my action script code I use. The cb is for checkbox and radio buttons says radio and the other informationis normal input text box. This is working pretty good. I have problem with the check box but that I can work on later to figure out. My main concern is how can I code this action script to work in a PHP form..please help.

import fl.controls.*;
import fl.controls.RadioButtonGroup;

//This sets a group name for the radio button instances.
var myradioGroup:RadioButtonGroup = new RadioButtonGroup("RadioButtonGroup");

//This assigns the radio button instances to the radio group.
cRadio1.group = myradioGroup;
cRadio2.group = myradioGroup;

submit_btn.addEventListener(MouseEvent.CLICK, submitFunc);
var radBtns = [cRadio1,cRadio2];
var errorsNum = 0;
function submitFunc(e:MouseEvent)
{
var finalData = "";
var errorFlag = "Followings errors were found.\n";
if (name_txt.text == "")
{
errorsNum++;
errorFlag += errorsNum+". Enter ur name.\n";
}
if (email_txt.text == "")
{
errorsNum++;
errorFlag += errorsNum+". Enter ur email.\n";
}
if (mobile.text == "")
{
errorsNum++;
errorFlag += errorsNum+". Enter ur phone number.\n";
}
if (!myradioGroup.selection)
{
errorsNum++;
errorFlag += errorsNum+". Select ur gender.\n";
}

if (age.selectedIndex < 0)
{
errorsNum++;
errorFlag += errorsNum+". Select any of the course.\n";
}
if (!orangecb.selected)
{
errorsNum++;
errorFlag += errorsNum+". Please check one";
}
if (!orangelcb.selected)
{
errorsNum++;
errorFlag += errorsNum+". Please check one";
}

if (message_txt.text == "")
{
errorsNum++;
errorFlag += errorsNum+". Enter ur message.\n";
}

if (errorsNum > 0)
{
mytxt.text = errorFlag;
errorFlag = "";
errorsNum = 0;
return false;
}

else
{
finalData += "Thank you "+name_txt.text+" for contacting me! I will call you at "+mobile.text+", "+"else I can mail you also at "+email_txt.text+" in "+applecb.selected+"response "+orangecb.selected+" of your message "+message_txt.text+"\n\n Your other information is, you're a "+myradioGroup.selection.value+" and is between "+age.value+"\nThanks";
mytxt.text = finalData;
}
}

Dani AI

Generated

A clear, reliable flow is: have the Flash/ActionScript send the form values to a small PHP endpoint (for example, send.php) using POST; the PHP script then validates and sanitizes every field, sends or queues the email, and returns a simple status string that Flash can display. The current ActionScript builds a local finalData string for display; instead map each control to named POST variables so the server receives exactly what it needs (name, email, mobile, gender, age, applecb, orangecb, orangelcb, message).

A minimal ActionScript pattern (map fields -> POST, then load) looks like this:

var vars:URLVariables = new URLVariables();
vars.name   = name_txt.text;
vars.email  = email_txt.text;
vars.mobile = mobile.text;
vars.gender = myradioGroup.selection ? myradioGroup.selection.value : "";
vars.apple  = applecb.selected ? "1" : "0"; // same idea for other checkboxes
var req:URLRequest = new URLRequest("send.php");
req.method = URLRequestMethod.POST;
req.data = vars;
var loader:URLLoader = new URLLoader();
loader.load(req);

On the PHP side: read $_POST keys that match the names sent from Flash, use trim() and filter_var($email, FILTER_VALIDATE_EMAIL) for email validation, and treat checkboxes with isset() (or name them as arrays like options[] for multiple selections). Strip CR/LF from any header fields (prevent header injection) and prefer sending mail through an authenticated SMTP library (PHPMailer/SMTP) if the host blocks or flags mail(). Also check mail() return value and server mail logs when troubleshooting.

Quick debugging tips: temporarily have send.php write print_r($_POST, true) to a logfile to confirm what Flash sends; test the PHP endpoint with a plain HTML form or curl to isolate Flash vs server issues; add a crossdomain.xml if the SWF and PHP are on different domains. The PHP example from is a useful start; ’s links also point to practical examples for integrating AS3 with PHP.

Recommended Answers

All 2 Replies

Here is a simple contact form in php. This checks if the fields are empty and if the email is valid using regex pattern. If all fields are correct the php will use the mail function to send the data to the myEmail value. This may not be what you need but if you review the code, it will give you some direction on how to build a php contact form.

<?php

    // Check if submit button has been pressed.
    if(isset($_POST['submit'])){
        //Create Var's from post array.
        $fname   = $_POST['fname'];
        $lname   = $_POST['lname'];
        $email   = $_POST['email'];
        $website = $_POST['website'];
        $message = $_POST['message'];

        //Email address to send information to.
        $myEmail = 'thisismyemail@xxxxx.com';


        $error = '';

        // Check if post values are empty. If values are empty, we are appending a
        // new error message string to the $error var.
        // New $error var would be $error = ''.'error message'.'error message'....
        // and so on. This will happen for each empty value.

        if($fname == ''){
            $error .= 'Please enter Firstname';
        }

        if($lname == ''){
            $error .= 'Please enter Lastname';
        }

        if($email == ''){
            $error .= 'Please enter Email';
        }

        //Create regex pattern for checking valid emails.
        $pattern = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$";

        if(!preg_match($pattern, $email)){
            $error .= 'Invalid Email';
        }

        if($website == ''){
            $error .= 'Please enter Website';
        }

        // If now error messages have been appended to the error var we can
        // build our email
        if($error == ''){

            $headers = 'From: Contact Form '." <$myEmail>\r\n" .
            'Reply-To: '.$email . "<$email>\r\n" .
            'X-Mailer: PHP/' . phpversion();
            $to = "$myEmail";
            $subject = 'New Email From Contact Form';
            $body = 'From: '.$fname . $lname."\r\n";
            $body .= 'Email: '.$email."\r\n\n";
            $body .= $message;
            $send_email = mail($to, $subject, $body,$headers, '-f'.$,myEmail);


        }else{
            //else we will echo our error message.
            echo $error;
        }

    }




?>
Member Avatar for Member #949455

Here is a couple of links about combining actionscript and php form:

Both links provide you a picture of the form plus provide a php code form!

I think you are closed to be done!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.