3 Replies Latest reply on Nov 27, 2009 5:40 AM by Ned Murphy

    Adding checkbox to flash form mailer

    PurplePplEtr

      I'm picking up where someone else left off, and I don't know the first thing about Action scripts or PHP.

      I have a flash form (Name, Email, Subject, Message) and I want to add a checkbox for "Add me to your mailing list"

      I've tried to break it down and logically figure it out, but no such luck, guess I'm not that smart.  :-)

      The mailer already works great, and I would just like to add a second line to the email with "Add to mail list: Yes/No"

      I named the checkbox "maillist"

       

      Here is the action script:

      var mainTL:MovieClip = this;

      submit_mc._alpha = 0;

      var dataSender:LoadVars = new LoadVars();

      var dataReceiver:LoadVars = new LoadVars();

      var formCheck:Object = new Object();
      formCheck.onKeyUp = function() {
      if (name_txt.text != '' &&
         email_txt.text != '' &&
         subject_txt.text != '' &&
         message_txt.text != '') {
        alert_txt.text = '';
        submit_mc._alpha = 50;
      } else {
        submit_mc._alpha = 0;
      }
      }

      Key.addListener(formCheck);

      var normal_border:Number = 0x7A7777;
      var focus_border:Number = 0xFA8D00;

      var normal_background:Number = 0xECECE6;
      var focus_background:Number = 0xE9E3E3;

      var normal_color:Number = 0x776D6C;
      var focus_color:Number = 0x000000;

      inputs=[name_txt,email_txt,subject_txt,message_txt];

      for( var elem in inputs) {
      inputs[elem].border = true;
      inputs[elem].borderColor = normal_border;
      inputs[elem].background = true;
      inputs[elem].backgroundColor = normal_background;
      inputs[elem].textColor = normal_color;
      inputs[elem].onSetFocus = function() {
        this.borderColor = focus_border;
        this.backgroundColor = focus_background;
        this.textColor = focus_color;
        }
      inputs[elem].onKillFocus = function() {
        this.borderColor = normal_border;
        this.backgroundColor = normal_background;
        this.textColor = normal_color;
      }
      }

      Selection.setFocus(name_txt);

      submit_mc.onRelease = function() {
      if (name_txt.text != '' &&
         email_txt.text != '' &&
         subject_txt.text != '' &&
         message_txt.text != '') {
        alert_txt.text='';

        mainTL.play();
        dataSender.name = name_txt.text;
        dataSender.email = email_txt.text;
        dataSender.subject = subject_txt.text;
        dataSender.message = message_txt.text;
        dataReceiver.onLoad = function() {
         if (this.response == "invalid") {
          mainTL.gotoAndStop(1);
          alert_txt.text = "Please enter valid email address."
         } else if (this.response == "passed") {
          mainTL.gotoAndStop(4);
         }
        }
        dataSender.sendAndLoad("processEmail.php", dataReceiver, "POST");
      } else {
        alert_txt.text = "Please fill in all fields.";
      }
      }

      And here is the PHP mailer:

      <?php

      $name=$_POST['name'];
      $email=$_POST['email'];
      $subject=$_POST['subject'];
      $message=$_POST['message'];
      $name=trim($name);
      $email=trim($email);
      $subject=StripSlashes($subject);
      $message=StripSlashes($message);

      ###########*/$toaddress='me@f.com';

      $toaddress='me@me.com'


      if (preg_match ("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af |ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs |bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk |dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov| gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke| kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm |mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|n u|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg |sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz |ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0 -9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5] [0-5]))$/i", $email)) {
          mail($toaddress,$subject,$message,"From: $name <$email>\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
           $name='';
           $email='';
           $subject='';
           $message='';
           echo "response=passed";
      } else {
        echo "response=invalid";
        exit;
      }

      ?>


      Any help would be greatly appreciated.

       

      Thanks in advance.

        • 1. Re: Adding checkbox to flash form mailer
          Ned Murphy Adobe Community Professional & MVP

          Here's a rough shot at a solution that only requires a change in one of the functions in the Flash code... adding the code shown in red...  this just skips a line at the end of the mesage and appends a line reflecting the checkbox status.  The red code I show replaces the line of code: dataSender.message = message_txt.text;

           

          submit_mc.onRelease = function() {
          if (name_txt.text != '' &&
             email_txt.text != '' &&
             subject_txt.text != '' &&
             message_txt.text != '') {
            alert_txt.text='';

            mainTL.play();

            dataSender.name = name_txt.text;
            dataSender.email = email_txt.text;
            dataSender.subject = subject_txt.text;

            if(maillist.selected){

                    dataSender.message = message_txt.text +"\n\nAdd to Mail List:  Yes";

            } else {

                    dataSender.message = message_txt.text +"\n\nAdd to Mail List:  No";

            }


            dataReceiver.onLoad = function() {
             if (this.response == "invalid") {
              mainTL.gotoAndStop(1);
              alert_txt.text = "Please enter valid email address."
             } else if (this.response == "passed") {
              mainTL.gotoAndStop(4);
             }
            }
            dataSender.sendAndLoad("processEmail.php", dataReceiver, "POST");
          } else {
            alert_txt.text = "Please fill in all fields.";
          }
          }

          • 2. Re: Adding checkbox to flash form mailer
            PurplePplEtr Level 1

            Ned,

             

            That was awesome!  Woked perfectly.

             

            Thank you very much for the help!