# Customizing AS3 form to add phone field

**URL:** <https://forum.kirupa.com/t/customizing-as3-form-to-add-phone-field/323525>\
**Category:** flash\
**Created:** [July 5, 2011, 1:53pm UTC](https://forum.kirupa.com/t/customizing-as3-form-to-add-phone-field/323525 "2011-07-05T13:53:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![4mula\_D](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/4mula_d/32/3958_2.png) [@4mula\_D](https://forum.kirupa.com/u/4mula_D)\
**Post date:** [July 5, 2011, 1:53pm UTC](https://forum.kirupa.com/t/customizing-as3-form-to-add-phone-field/323525/1 "2011-07-05T13:53:59Z")

</div>

The AS3 form and php code are posted below. I have modified the code to my desired layout however the phone number will not post to the email. I receive an email with the name and email address but no phone number. Can someone please assist me in resolving this issue. Thanks in advance.

**contact.php**

\<?php  
$contact\_name = $\_POST[‘name’];  
$contact\_email = $\_POST[‘email’];  
$contact\_phone = $\_POST[‘phone’];

if( $contact\_name == true )  
{  
$sender = $contact\_email;  
$receiver = “[demetrius.mcclain@dmcclain.co.cc](mailto:demetrius.mcclain@dmcclain.co.cc)”;  
$client\_ip = $\_SERVER[‘REMOTE\_ADDR’];  
$email\_body = "Name: $contact\_name  
Email: $sender  
Phone: $contact\_phone

IP: $client\_ip";  
$extra = "From: $sender  
" . "Reply-To: $sender  
" . “X-Mailer: PHP/” . phpversion();  
if( mail( $receiver, $contact\_subject, $email\_body, $extra ) )  
{  
echo “success=yes”;  
}  
else  
{  
echo “success=no”;  
}  
}  
?\>

**ContactMain**

package  
{  
import flash.display.MovieClip;  
import flash.events.MouseEvent;  
import flash.events.FocusEvent;  
import flash.events.Event;  
import flash.events.TimerEvent;  
import flash.text.TextField;  
import flash.utils.Timer;  
import flash.net.URLLoader;  
import flash.net.URLRequest;  
import flash.net.URLVariables;  
import flash.net.URLRequestMethod;  
import flash.net.URLLoaderDataFormat;

/\*\*

- ContactForm Version 1
- 
- @author activetofocus team
- @since 2010-02-27  
\*/  
public class ContactMain extends MovieClip  
{  
//--------------------------------------  
// Variables  
//--------------------------------------  
private var timer:Timer;  
private var urlload:URLLoader;  
private var urlrequest:URLRequest;

/\*\*  
\* constructor  
\*/  
public function ContactMain()  
{

}  
//--------------------------------------  
// Function  
//--------------------------------------

/\*\*

- data init  
\*/  
public function init():void  
{  
state\_mc.visible = false;

clear\_btn.buttonMode = true;  
clear\_btn.addEventListener(MouseEvent.CLICK,onBtnMouseClickEvent);  
clear\_btn.addEventListener(MouseEvent.MOUSE\_OVER,onBtnMouseOverEvent);  
clear\_btn.addEventListener(MouseEvent.MOUSE\_OUT,onBtnMouseOutEvent);

send\_btn.buttonMode = true;  
send\_btn.addEventListener(MouseEvent.CLICK,onBtnMouseClickEvent);  
send\_btn.addEventListener(MouseEvent.MOUSE\_OVER,onBtnMouseOverEvent);  
send\_btn.addEventListener(MouseEvent.MOUSE\_OUT,onBtnMouseOutEvent);

name\_txt.addEventListener(FocusEvent.FOCUS\_IN,onTextFocusInEvent);  
name\_txt.addEventListener(FocusEvent.FOCUS\_OUT,onTextFocusOutEvent);

mail\_txt.addEventListener(FocusEvent.FOCUS\_IN,onTextFocusInEvent);  
mail\_txt.addEventListener(FocusEvent.FOCUS\_OUT,onTextFocusOutEvent);

phone\_txt.addEventListener(FocusEvent.FOCUS\_IN,onTextFocusInEvent);  
phone\_txt.addEventListener(FocusEvent.FOCUS\_OUT,onTextFocusOutEvent);

}  
/\*\*  
\* check name textfield  
_/  
private function checkNameText():void  
{  
if(name\_txt.text == “”)  
{  
//name\_error.visible = true;  
name\_txt.text = “Please enter your name!”;  
}  
else  
{  
//name\_right.visible = true;  
}  
}  
/_\*

- check mail textfield  
\*/  
private function checkMailText():void  
{  
if(mail\_txt.text == “”)  
{  
//mail\_error.visible = true;  
mail\_txt.text = “Please enter your email!”;  
}  
else  
if(!authenticationEmail(mail\_txt.text))  
{  
//mail\_error.visible = true;  
mail\_txt.text = “Please enter a valid email!”;  
}  
else  
{  
//mail\_right.visible = true;  
}  
}

/\*\*

- check phone text field  
\*/  
private function checkphoneText():void  
{  
if(phone\_txt.text == “”)  
{  
//phone\_error.visible = true;  
phone\_txt.text = “Please enter phone number!”;  
}  
else  
{

}  
}  
/\*\*  
\* check message textfield  
_/  
/_\*

- set click state  
\*/  
private function setClickState(bool:Boolean = false):void  
{  
name\_txt.mouseEnabled = bool;  
mail\_txt.mouseEnabled = bool;  
phone\_txt.mouseEnabled = bool;  
clear\_btn.mouseEnabled = bool;  
send\_btn.mouseEnabled = bool;  
}

/\*\*

- authentication email format  
\*/  
private function authenticationEmail(str:String):Boolean  
{  
var p:RegExp = /(\w|[\_.-])+@((\w|-)+.)+\w{2,4}+/;  
var r:Object = p.exec(str);  
if( r == null )  
{  
return false;  
}  
return true;  
}

//--------------------------------------  
// Event  
//--------------------------------------  
/\*\*

- clear,send button mouse click event  
\*/  
private function onBtnMouseClickEvent(evt:MouseEvent):void  
{  
if(state\_mc.visible) state\_mc.visible = false;  
if(evt.currentTarget == clear\_btn)  
{  
name\_txt.text = “”;  
mail\_txt.text = “”;  
phone\_txt.text = “”;

}  
else  
{

```
if(name_txt.text !="" && mail_txt.text != "" && phone_txt.text != "")
{
 if(authenticationEmail(mail_txt.text))
 {    
  setClickState();

  state_mc.gotoAndStop(1);
  state_mc.visible = true;

  urlload = new URLLoader;
  urlrequest = new URLRequest( "contact.php" );
  urlrequest.method = URLRequestMethod.POST;

  var dataStr:String = "name=" + name_txt.text
         + "&email=" + mail_txt.text
      + "&phone=" + phone_txt.text;
         
  var urlVar:URLVariables = new URLVariables(dataStr);
  urlVar.dataFormat = URLLoaderDataFormat.TEXT;
  urlrequest.data = urlVar;

  urlload.load(urlrequest);
  urlload.addEventListener(Event.COMPLETE,onLoadCompleteEvent);

  timer = new Timer(2500,1);
  timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerCompleteEvent);
  timer.start();
 }
 else
 {
  checkMailText();
 }
}
else
{
 checkNameText();
 checkMailText();
 checkphoneText();
 
}

```

}  
}  
/\*\*  
\* clear,send button mouse over event  
_/  
private function onBtnMouseOverEvent(evt:MouseEvent):void  
{  
evt.currentTarget.gotoAndStop(2);  
}  
/_\*

- clear,send button mouse uut event  
_/  
private function onBtnMouseOutEvent(evt:MouseEvent):void  
{  
evt.currentTarget.gotoAndStop(1);  
}  
/_\*
- textField get focus event  
\*/  
private function onTextFocusInEvent(evt:FocusEvent):void  
{  
if(state\_mc.visible) state\_mc.visible = false;  
if(evt.currentTarget == name\_txt)  
{  
if(name\_txt.text == “Please enter your name!”) name\_txt.text = “”;  
name\_mc.gotoAndStop(2);  
}  
else  
if(evt.currentTarget == mail\_txt)  
{  
if(mail\_txt.text == “Please enter your email!” || mail\_txt.text == “Please enter a valid email!”) mail\_txt.text = “”;  
mail\_mc.gotoAndStop(2);  
}  
else  
if(evt.currentTarget == phone\_txt)  
{  
if(phone\_txt.text == “Please enter phone number!”) phone\_txt.text = “”;  
phone\_mc.gotoAndStop(2);  
}

}  
/\*\*

- textField focus out event  
\*/  
private function onTextFocusOutEvent(evt:FocusEvent):void  
{  
if(evt.currentTarget == name\_txt)  
{  
name\_mc.gotoAndStop(1);  
checkNameText();  
}  
else  
if(evt.currentTarget == mail\_txt)  
{  
mail\_mc.gotoAndStop(1);  
checkMailText();  
}  
else  
if(evt.currentTarget == phone\_txt)  
{  
phone\_mc.gotoAndStop(1);  
checkphoneText();  
}

}  
/\*\*

- send complete event  
\*/  
private function onLoadCompleteEvent(evt:Event):void  
{  
timer.removeEventListener(TimerEvent.TIMER\_COMPLETE,onTimerCompleteEvent);  
timer.stop();

var backInfo = new URLVariables(evt.currentTarget.data).success;

if(backInfo == “yes” )  
{  
state\_mc.gotoAndStop(3);

```
name_txt.text = "";
mail_txt.text = "";
phone_txt.text = "";

```

}  
else  
{  
state\_mc.gotoAndStop(2);  
}  
setClickState(true);  
}  
/\*\*

- timer complete event  
\*/  
private function onTimerCompleteEvent(evt:TimerEvent):void  
{  
urlload.removeEventListener(Event.COMPLETE,onLoadCompleteEvent);  
timer.removeEventListener(TimerEvent.TIMER\_COMPLETE,onTimerCompleteEvent);  
setClickState(true);  
state\_mc.gotoAndStop(2);  
}  
}  
}
