Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating eMail form using components.

Guest
Apr 03, 2013 Apr 03, 2013

Hello,

i need some help with creating this email form in flash for my website.  i have found some various tutorials and methods but none seem to work.  Obviously i'm doing something wrong since it appears to work in the video tutorials. 

So here is my issue....

I'm using AS3. My code is pasted below.  Whith this code when I publish to view my website, at first it all seems ok.  I can go through all the pages fine.  the problem comes when i go to the CONTACT form page.  first time i enter the page, it looks fine...than when i go to another page and come back to the contact page the form dissappears. 

my form is placed on frame 11 of my main timeline, inside a movie clip named contact.

----------------------------------------------------

import fl.controls.Button

import fl.controls.TextArea

import fl.controls.TextInput

//hide processingMC

processingMC.visible=false;

sendBTN.addEventListener(MouseEvent.CLICK, sendMessage);

function sendMessage(e:MouseEvent):void{

var my_vars:URLVariables = new URLVariables();

my_vars.senderName = firstName.text;

my_vars.senderNamelast = lastName.text;

my_vars.senderPhone = phone.text;

my_vars.senderEmail = eMail.text;

my_vars.senderMsg = msg.text;

var my_url:URLRequest = new URLRequest("my_form.php");

my_url.method = URLRequestMethod.POST;

my_url.data = my_vars;

var my_loader:URLLoader = new URLLoader();

my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;

my_loader.load(my_url);

firstName.text = "";

lastName.text = "";

phone.text = "";

subject.text = "";

eMail.text = "";

msg.text = "Message Sent";

}

---------------------------

my_form.php file looks like this....

<?php

$to = "vish92683@yahoo.com";

$subject = ($_POST['senderName','senderNamelast]);

$message = ($_POST['senderMsg']);

$message .= "\n\n---------------------------\n";

$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";

$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";

if(@mail($to, $subject, $message, $headers))

{

echo "answer=ok";

}

else

{

echo "answer=error";

}

?>

----------------------------

what am i missing?

TOPICS
ActionScript
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 03, 2013 Apr 03, 2013

if you are not getting any errors,

trace out the position of the playhead on the timeline when this happens

//trace(this.currentFrame)

make sure you are at the right position where your form actually "lives"

also:

understand that every time you revisit a frame the whole code that keyframe holds is processed again and again.

to test if the communication with the server has anything to do with your problems:

make a seperate fla where you only test the forms logic.

if that works: for reusability you might consider loading this form.swf via a loader on stage, when you need it (when the user clicks on the form button or whatever)

and remove it when he clicks the send button.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 04, 2013 Apr 04, 2013

Moccamaximum,

Thank you for your feedback.  I will try what you said.  I think it would be a good idea to have the form.swf load up as needed.  This way i can utilize this form easily in my other projects.

i did have one question though....as far as coding is conserned, what is an easier way to create this form?  is using the component elements easier or creating the elements from scratch?

Thanks again for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 04, 2013 Apr 04, 2013

Components have no real value if you don´t use them application-wide. If you only use them in your form and nowhere else, they only produce overhead.

They are not easily customized and they behave differently (sometimes counterintuitively) than simple MovieClips or Sprites.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 05, 2013 Apr 05, 2013

thank you...this information helps a lot. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 09, 2013 Apr 09, 2013

so I think I am making some progress hrere.  I was able to get the form show up where I need it.  It is not a seperate SWF file that gets loaded as needed.  I tried that approach but wasnt working well.  

I am getting this error when I publish out my prjoject...

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/drawNow()

          at fl.controls::ScrollBar/draw()

          at fl.controls::UIScrollBar/draw()

          at fl.core::UIComponent/drawNow()

          at fl.controls::TextArea/updateScrollBars()

          at fl.controls::TextArea/drawLayout()

          at fl.controls::TextArea/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/drawNow()

          at fl.controls::ScrollBar/draw()

          at fl.controls::UIScrollBar/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::LabelButton/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/drawNow()

          at fl.controls::ScrollBar/draw()

          at fl.controls::UIScrollBar/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::LabelButton/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChildAt()

          at fl.controls::BaseButton/drawBackground()

          at fl.controls::BaseButton/draw()

          at fl.core::UIComponent/drawNow()

          at fl.controls::ScrollBar/draw()

          at fl.controls::UIScrollBar/draw()

          at fl.core::UIComponent/drawNow()

          at fl.controls::TextArea/updateScrollBars()

          at fl.controls::TextArea/drawLayout()

          at fl.controls::TextArea/draw()

          at fl.core::UIComponent/callLaterDispatcher()

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at vish_graphics_2013_fla::formMC_25/frame2()

          at flash.display::MovieClip/gotoAndStop()

          at vish_graphics_2013_fla::formMC_25/ValidateAndSend()

-------------------------------------------------------------------------------------------------------

here is my code for the form..

stop();

import fl.controls.TextInput;

import fl.controls.TextArea;

import fl.controls.UIScrollBar;

import fl.controls.Button;

import flash.events.*;

import flash.net.URLLoader;

import flash.net.URLLoaderDataFormat;

import flash.net.URLRequest;

// ----------------------------------------------------------------

var variables:URLVariables = new URLVariables();

// Be sure to change this URL to the PHP parse file on your site server

var varSend:URLRequest = new URLRequest("http://www.vishgraphics.com/contact_parse.php");

var varLoader:URLLoader = new URLLoader;

varSend.method = URLRequestMethod.POST;

varSend.data = variables;

statusTxt.text = "";

sendBtn.addEventListener(MouseEvent.CLICK, ValidateAndSend);

function ValidateAndSend(event:MouseEvent):void{

 

    //validate form fields

          if(!firstName.length) {

                    statusTxt.text = "Please enter your name.";

          } else if (!lastName.length) {

                    statusTxt.text = "Please enter your last name.";

          } else if(!eMail.length) {

                    statusTxt.text = "Please enter an email address";

          } else if(!validateEmail(eMail.text)) {

                    statusTxt.text = "Please enter a VALID email address";

          } else if(!msg.length) {

                    statusTxt.text = "Please enter a message.";

          } else {

 

statusTxt.text = "Thanks " + firstName.text + ", your message has been sent!";

 

                      variables.userName = firstName.text;

                    variables.userLastName = lastName.text;

                       variables.userEmail = eMail.text;

                       variables.userMsg = msg.text;

                       varLoader.load(varSend);

                    gotoAndStop(2);

 

          }

}

function validateEmail(str:String):Boolean {

          var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;

          var result:Object = pattern.exec(str);

          if(result == null) {

                    return false;

          }

          return true;

}

-----------------------

Any help would be great, as i have been struggling with this for some time now. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 10, 2013 Apr 10, 2013

the validation of your form fields is faulty.

Assuming you have Textinput-Field-instances called "firstName" on the highest level of your form all the conditons should be written like this:

if(firstName.text.length == 0)....

this should get rid of the 1009 error at the end

the 2007 seems to indicate some problems with components in your Main file,

to get better dedugging (with line hints) allow debugging in your Main file (under publishing options)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2013 Apr 10, 2013

I will give this a shot....thanks.

I have a different form up on the site currently.  Still not working properly.  But did get farther than where i was before i started this thread.  The weird thing is that when i preview the form by its self it looks fine.  i can read the input text field labels and can even type in the fields and can clearly read that text as well.  But when i go to my main website and code in to load the form.swf from my pc, I cant seem to make out the field labels, I cant type anything in the fields.  when i click in the text field the curser blinks once and it goes away.  Not only that the animation seems to slow down a lot when i go to the contact page.  you can take a look and see what i mean...just go to www.vishgraphics.com and click the "contact" button.

I tried using components and other forms...they all work well on there own..but when i pbulish it, save it and try to load it in when i enter the contact page..it changes on me...it comes up but like i said, cant type anything in it...cursor blinks onces and it goes away...

any idea?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 10, 2013 Apr 10, 2013

Your form doesn`t work for me, too.

This code in your form.as is unnecessary:

import fl.controls.TextInput;

import fl.controls.TextArea;

import fl.controls.UIScrollBar;

import fl.controls.Button;

The components have to be present in the library of your fla file.

also: if you have the need of a stop() on the fist frame of your form:

put the stop() at the end of the code you want to get executed, or at least after the import statements

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2013 Apr 10, 2013

ok i will give that a try later when i get out of work....thank you for your help this.  I really appriciate it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 28, 2013 Jun 28, 2013

Hi, I'm very new to Flash and have no knowledge of PHP at all. I'm experienced in coding so I just need to learn syntax and such for whatever language. I'm creating a wed-site with flash CS6 and have  created my CONTACT_US email form in Flash. My flash code is very similar to your initial post.

// handle sending message out to URL for site

ContactUs_mc.SubmitMsg_btn.addEventListener(MouseEvent.CLICK, ContactSendMsg);

function ContactSendMsg(event:MouseEvent):void

{

  // check to see if all of the fields are filled.

          if (ContactUs_mc.theName_txt.text == "" ||

                    ContactUs_mc.theEmail_txt.text == "" ||

                    ContactUs_mc.thePhone_txt.text == "" ||

                    ContactUs_mc.theComment_txt.text == "")

          {

                    ContactUs_mc.theFeedback_txt.text = "Please fill out all of the fields."

          }

          else

          {

                    // Get the data from the field variables and put into a container

//                    var ContactVars.URLVariables = new URLVariables();

//

//                    ContactVars.name = ContactUs_mc.theName_txt.text;

//                    ContactVars.email  = ContactUs_mc.theEmail_txt.text;

//                    ContactVars.PhoneNumber  = ContactUs_mc.thePhone_txt.text;

//                    ContactVars.message  = ContactUs_mc.theComment_txt.text;

//

//                    // Link data to the form and send the data

//                    var MailAddress.URLRequest = new URLRequest("http://www.islandanimationstudio.com/Yahooform.php");

//                    MailAddress.data = ContactVars;

//                    MailAddress.method = URLRequestMethod.POST;

//                    sendToURL(MailAddress);

                    // tell user what happened and clean up fields

                    ContactUs_mc.theFeedback_txt.text = "Thank you. Message has been sent."

                    ContactUs_mc.theName_txt.text = "";

                    ContactUs_mc.theEmail_txt.text = "";

                    ContactUs_mc.thePhone_txt.text = "";

                    ContactUs_mc.theComment_txt.text = "";

          }

          // End your custom code

} // end function

It only has simple field validation at the moment. The email code is commented out since I have no "Yahooform.php" file created. I need to learn how to create one and how and where to upload it to my Yahoo account. So, my question is what tutorials did you view to learn how to create the php file and how and where to upload that file to Yahoo?

Any guidance you can provide is greatly appreciated.

Thanks,

P.S. I like your site

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 30, 2013 Jun 30, 2013

I´m not overly familiar with the details about how to connect with Yahoos webservicesw. But you should get an idea how to setup ypur php file here

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2013 Jul 01, 2013

Hi,

Thanks for this. I'll look at it.

In the mean time I've created a php file and the action script to interface with it. When I run the flash file (.swf) it appears as if the message is sent (based on my trace statements, but I never receive the message in my email account at Yahoo. I know the yahoo account  is working. I've sent emails to it from a seperate email account from a different provider.

Does anyone see any reason why this is not working? It seems to run fine for the tutorial I'm following.

There seems to be many ways to connect flash to php. Perhaps there is a more simple solution.

All help is appreciated.

The following is the code for the  php form/"file".


<?php

 

$name_text =  $_POST['name_text'];

$subject_text = $_POST['subject_text'];

$email_text = $_POST['email_text'];

$phoneNum_text = $_POST['phoneNum_text'];

$comment_text =  $_POST['comment_text'];

if ($email_text != NULL){  //

          $from = $email_text;

          $headers = "From: $from";

          $email_to = 'jeffrey@islandanimationstudio.com';

          $subject = "Subject: " . $subject_text . "\n";

          $message  = "Name: " . $name_text .  "\n";

          $message  .= "Phone: " . $phoneNum_text  . "\n\n";

          $message .= "Email: " . $email_text     . "\n\n";

          $message .= "Comments: \n" . $comment_text . "\n\n";

 

          ini_set('sendmail_from', $from ); //

 

          mail($email_to , $subject , $message, $headers ); // sends an email

 

          // the following line was always somewhat optional. I've noticed with Flash 10, its best just to leave it out.

          echo 'var1=yes&successMessage=Your Email Was Sent';

 

}

else

{

                    echo 'var2=No&successMessage=Your Email was NOT sent';

}

?>

Below is the action script code I'm using that interfaces with this php file.

// handle sending message out to URL for site

ContactUs_mc.SubmitMsg_btn.addEventListener(MouseEvent.CLICK, ContactSendMsg);

function ContactSendMsg(event:MouseEvent):void

{

          // check to see if all of the fields are filled.

          if (ContactUs_mc.theName_txt.text == "" ||

                    ContactUs_mc.theSubject_txt.text == "" ||

                    ContactUs_mc.theEmailAddr_txt.text == "" ||

                    ContactUs_mc.thePhoneNum_txt.text == "" ||

                    ContactUs_mc.theComment_txt.text == "")

          {

                    ContactUs_mc.theFeedback_txt.text = "Please fill out all of the fields.";

          }

          else

          {

                    // confirm email address is valid at some level.

                     // i.e. Does it have an @ symbol and period.

                    if ( ContactUs_mc.theEmailAddr_txt.text.indexOf("@" ) == -1  ||

                               ContactUs_mc.theEmailAddr_txt.text.indexOf("." ) == -1 )

                    {

                              ContactUs_mc.theFeedback_txt.text = "Please enter a valid email address.";

                    }

                    else

                    {

                              // Get the data from the field variables and put into a container

                              var ContactVars:URLVariables = new URLVariables();

 

                              ContactVars.name_text = ContactUs_mc.theName_txt.text;

                              ContactVars.subject_text  = ContactUs_mc.theSubject_txt.text;

                              ContactVars.email_text  = ContactUs_mc.theEmailAddr_txt.text;

                              ContactVars.phoneNum_text  = ContactUs_mc.thePhoneNum_txt.text;

                              ContactVars.comment_text  = ContactUs_mc.theComment_txt.text;

 

                 //trace (ContactVars.name_text); // = ContactUs_mc.theName_txt.text;

                 //trace (ContactVars.subject_text); //  = ContactUs_mc.theSubject_txt.text;

                 //trace (ContactVars.email_text); //  = ContactUs_mc.theEmailAddr_txt.text;

                 //trace (ContactVars.phoneNum_text); //  = ContactUs_mc.thePhoneNum_txt.text;

                 //trace (ContactVars.comment_text);  //  = ContactUs_mc.theComment_txt.text;

 

                              // Link data to the form and send the data

                              var request:URLRequest = new URLRequest();

                              request.url = "http://www.islandanimationstudio.com/PHPForms/AISEmailform.php";

                              request.data = ContactVars;

                              request.method = URLRequestMethod.POST;

 

                              // create a loader in order to send the email via php file.

                              // sendToURL(MailAddress); // I tried this method as well instead of the loader below, but it did not work either

                              var loader:URLLoader = new URLLoader();

                              //loader.dataFormat = URLLoaderDataFormat.TEXT;   //or you can use this line instead of the following one.

                              loader.dataFormat = URLLoaderDataFormat.VARIABLES;

                              loader.addEventListener(Event.COMPLETE, MessageSendCompleteHandler);

                              try

                              {

                                        // loader.load(MailAddressRequest);

                                        loader.load(request);

                                        ContactUs_mc.theFeedback_txt.text = "Sending...";

                                        trace("Sending...");

                              } catch (error:Error)

                              {

                                        trace("Failed" + error.message);

                                        ContactUs_mc.theFeedback_txt.text = "Unable to send form";

                              }

 

                                        trace("Post Catch");

 

                              function MessageSendCompleteHandler(event:Event):void

                              {

                      //trace("ENTER MessageSendCompleteHandler");

                      //trace (event.target.data.successMessage); //returns the message in the PHP file.

                                        // tell user what happened and clean up fields

                                        ContactUs_mc.theFeedback_txt.text = "Thank you. You're email has been sent."

                                        ContactUs_mc.theName_txt.text = "";

                                        ContactUs_mc.theSubject_txt.text = "";

                                        ContactUs_mc.theEmailAddr_txt.text = "";

                                        ContactUs_mc.thePhoneNum_txt.text = "";

                                        ContactUs_mc.theComment_txt.text = "";

                       //      trace("                    EXIT MessageSendCompleteHandler");

                              }   // end function MessageSendCompleteHandler

                    }

          }

} // end function ContactSendMsg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 01, 2013 Jul 01, 2013
LATEST

even if you manage to get rid of all the errors your code might throw, you have to understand the "inner workings" of how the server you upload your flash+php handles the sending of the mail.

A typical server would most likely only allow to send a mail via its mail service if the file that triggers the mailing sits in the same directory as the php file, so its likely that -since you are using absolute paths ( "

"http://www.islandanimationstudio.com/PHPForms/AISEmailform.php")

you might run into a security issue. You can either find that out by imlementing a Listener for a HTTPStatusEvent or simply upload the swf to the directory of your php file and check if it works from there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines