Sending data form SWF using PHP script

 

The goal is to show how to get data from a swf form and to send a mail using a PHP script.

Creating a form has already been explained. I'll only mention how to adapt stuff.

Creating Objects

You 'd get someting like :

1 - Set up movie size 640x480 and background color : #000066. Any Frame Rate 'll fit.

2 - It's practically same thing as developed in first example mentioned. Get the whole in images !

Reset button to clear data form. Envoyer (to send) 'll delivery data to PHP script which 'll send out mail.
All texts field_..... 'll be of INPUT type, for data.
Above all, I'll explain how to create radiobutton to select Mr, Mrs or Miss.
Buttons Monsieur, Madame, Maidchen 'll be created to make selection ready to go.

3 - Watch out pictures and reproduce.

Framework = rectangle

CADRE  CADRE

Title bar = rectangle

BARRE TITRE  BARRE TITRE

Title = static text

COURRIER  COURRIER

Civil = static text

CIVILITE  CIVILITE

4 - Button Monsieur :
Text and circle container.

static text

Texte MONSIEUR  Texte MONSIEUR

Circle

CERCLE MONSIEUR  CERCLE MONSIEUR

5 - Group as button.

BOUTON MONSIEUR

Change text color when mouse Over.

6 - Proceed in the same way for button Madame, but X must change :
text : X = 228 circle X = 215

7 - Proceed in the same way for button Maidchen, but X must change :
text : X = 298 circle X = 285

8 - Create now the dot : it 'll move to a place depending on button clicked.

Circle

DOT  DOT

9 - Right now, fields labels :

static text

LABEL  LABEL

10 - Input fields :

NAME

NOM  NOM

FIRST NAME

PRENOM  PRENOM

CITY

VILLE  VILLE

SUBJECT

SUJET  SUJET

MESSAGE

MESSAGE  MESSAGE

11 - Well, I let you taking care of creating buttons Envoyer (=Send) and Reset as they have been described in a previous example. Just change X and Y. I'll show scripts further in this page.

SwishMax scripts

In Outline, select Scene_1, Expert Mode. Enter the following script :

function reset()
{ // reset radiobutton and variables
      dot._X = 154;
      civil = "Monsieur";
      nom= "";
      prenom= "";
      ville= "";
      sujet= "";
      message= "";
}
onLoad ()
{ // init radiobutton
       dot._X = 154; // center over Mr
       civil = "Monsieur";
}
onFrame (20,afterPlacedObjectEvents) { stop(); }

In Outline, select Reset. Enter the following script :

on(press)
{
       _root.reset();
       gotoSceneandPlay("<current scene>",1);
}

In Outline, select Envoyer. Enter the following script :

on(press)
{ // variables x...... are picked up by PHP script
       xcivil = civil;
       xnom = nom;
       xprenom = prenom;
       xville = ville;
       xsujet = sujet;
       xmessage = message;
       // let's send to PHP script
       _root.loadVariablesNum("mail.php",0,'POST');
       gotoSceneandPlay("<current scene>",1);
}

In Outline, select Maidchen. Enter the following script :

on (press)
{
       _root.civil = "Melle"; // affecte une valeur à la variable
       _root.dot._X= 285; // centre du bouton radio
}

In Outline, select Madame. Enter the following script :

on (press)
{
       _root.civil = "Madame";
       _root.dot._X= 215;
}

In Outline, select Monsieur. Enter the following script :

on (press)
{
       _root.civil = "Monsieur";
       _root.dot._X= 154;
}

PHP Script

Open your text editor, enter :

<?
// xcivil, xnom, xprenom, xville, xsujet, xmessage came from SWF
$data = array();
$data[0] = $_POST['xcivil'] ;
$data[1] = $_POST['xnom'] ;
$data[2] = $_POST['xprenom'] ;
$data[3] = $_POST['xville'] ;
$data[4] = $_POST['xsujet'] ;
$data[5] = $_POST['xmessage'] ;
/* if all fields have been filled out, lets's go civil variable doesn't matter */
$checksum = 0;
for ($i=1; $i<6; $i++)
{
      if ($data[$i] != "")
      { // throw out html data and avoid special chars
            $data[$i] = AddSlashes(strip_tags($data[$i]));
            $checksum++;
      }
}
if ( $checksum == 5 )
{ // tall is ok, let's post
      $to = "moi@mondomaine.kekpart"; // replace with your email
      $expediteur = "Chepaqui"; // sender not defined !
      /* headers : errors, From cc's, bcc's, etc */
      $headers = "From:".$expediteur."\r\n";
      $headers .= "X-Sender: \n";      // .= means concat
      $headers .= "X-Mailer: \n"; // mailer
      $headers .= "X-Priority: 1\n";
      $headers .= "Return-Path: \n"; // path error
      $headers .= 'MIME-Version: 1.0' . "\r\n"; // MIME
      $headers .= "Content-Type: text/html; charset=iso-8859-1\n";
      /* off it goes
       html formatted text, for instance : Mr Julius Cesar from Rome wrote */
      $texte = "<html>".$data[0]." ".$data[2]." ".$data[1]." de ".$data[3]." écrit<br>";
      // message ( point = concat )
      $texte .= "<br>".$data[5]."</html>";
      // ??? Does your host allow PHP mail function ???
      @mail ($to, $data[4], $texte, $headers);// @ to avoid host server displaying error message
} // end if checksum
else echo '<SCRIPT language="JAVASCRIPT">alert("All fields must be filled in, please.");</SCRIPT>';
?>

Save this file asmail.php (same name as in SwishMax script). You could test in localhost if you have installed Apache server and php.

 


Si vous aimez le site

 

Select a language if you need :


Page chargée en 0.004 sec.

Dernière Modification : Mer 25 Janvier 2017 8:56
Copyright © 1999-2017 Jean-Paul Molina Tous droits réservés.

to Google