dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Flash/php contact form

  1. #1
    Member
    Join Date
    Jul 2003
    Posts
    95

    Flash/php contact form

    Hi,
    I am wondering if somebody could help me with this contact form. Basically it work but I need two new fields for date and time. I assumed it would just be a case of duplicate the actionscript for one of the other fields and simply changing its anem say from 'message' to 'date'. Whenever I upload the swf/fla the original field work but the new ones dont.

    I have included the actionscript/PHP below. anywhere it has date/time are the new fields I have created. Also please note the A.S is quite long winded and contians alot of A.S that wouldnt relevant but I decided just to include it anyway. Its commented though so it shouldnt be too difficult to work out whats relevant and whats not.

    Thanks very much for your help.


    Actionscript:

    Code:
     //presistant reference to this movie's mail timeline:
    var mainTL:MovieClip = this;
    
    //start off with submit button dimmed
    submit_mc._alpha = 40;
    
    //create the LoadVars objects which will be used later
    //one to send the data...
    var dataSender:LoadVars = new LoadVars();
    
    //and one to recieve what comes back
    var dataReceiver:LoadVars = new LoadVars();
    
    /*
    create listener for Key Object
    this is just a U.I. thing - "wakes up" the submit button
    when all fields have at least some content
    */
    
    var formCheck:Object = new Object();
    formCheck.onKeyUp = function() {
    	if (name_txt.text != '' &&
    			email_txt.text != '' &&
    			subject_txt.text != '' &&
    			date_txt.text != '' &&
    			time_txt.text != '' &&
    			message_txt.text != '') {
    		//clear any alert messages
    		alert_txt.text = '';
    		//enable the submit button
    		submit_mc._alpha = 100;
    	} else {
    		//remain disabled until all fields have content
    		submit_mc._alpha = 40;
    	}
    }
    
    Key.addListener(formCheck);
    
    /*#######SET STYLES FOR TEXT FIELDS#######*/
    
    //define styles for both normal and focussed
    //set hex values here that work with your site's colors
    
    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;
    
    //create an array containing the fields we wish to have styles applied to
    
    inputs=[name_txt,email_txt,subject_txt,date_txt,time_txt,message_txt];
    
    /*
    a "for in" loop now iterates through each element in the "inputs" array
    and applies our "normal" formatting to each input text field
    */
    
    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;
    	/*this takes care of applying the "normal" style to each of the four input fields;
    		the following TextField prototypes handle highlighting when an input field
    		gains focus and resetting to normal when a field loses focus*/
    	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;
    	}
    }
    
    //finally: make the first field (name_txt) selected when the movie loads
    
    Selection.setFocus(name_txt);
    
    /*DEFINE SUBMIT BUTTON BEHAVIOR*/
    
    submit_mc.onRelease = function() {
    	//final check to make sure fields are completed
    	if (name_txt.text != '' &&
    			email_txt.text != '' &&
    			subject_txt.text != '' &&
    			date_txt.text != '' &&
    			time_txt.text != '' &&
    			message_txt.text != '') {
    		alert_txt.text='';//clear any previous error messages or warnings
    		//advance playhead to frame 2 - the "processing" message
    		mainTL.play();
    		//assign properties to LoadVars object created previously
    		dataSender.name = name_txt.text;
    		dataSender.email = email_txt.text;
    		dataSender.subject = subject_txt.text;
    		dataSender.date = date_txt.text;
    		dataSender.time = time_txt.text;
    		dataSender.message = message_txt.text;
    		//callback function - how to handle what comes abck
    		dataReceiver.onLoad = function() {
    			if (this.response == "invalid") {
    				mainTL.gotoAndStop(1);
    				alert_txt.text = "Please check email address - does not appear valid."
    			} else if (this.response == "passed") {
    				mainTL.gotoAndStop(4);
    			}
    		}
    		//now send data to script
    		/*************************
    		NOTE: the line below presumes the Flash swf file and php script are in the
    		SAME DIRECTORY on your server. If this is not the case (if for example you
    		wish to put the php script along with other similar items in a "scripts"
    		directory) you MUST MODIFY THE PATH. Otherwise the Flash movie won't be
    		able to locate the php script.
    		*************************/
    		dataSender.sendAndLoad("processEmail.php", dataReceiver, "POST");
    	} else {
    		//warning if they try to submit before completing
    		alert_txt.text = "Please complete all fields before submitting form.";
    	}
    }

    PHP

    PHP Code:

    <?php

    ini_set 
    ("sendmail_from","myemail");

    //create short variable names
    $name=$_POST['name'];
    $email=$_POST['email'];

    /*---*/
    $date=$_POST['date'];
    $time=$_POST['time'];
    /*---*/

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

    /*---*/
    $date=trim($date);
    $time=trim($time);
    /*---*/

    $subject=StripSlashes($subject);
    $message=StripSlashes($message);

    /*#########
    modify the next line with your own email address
    ###########*/

    $toaddress='myemail';


    if (
    mail($toaddress,$subject,$message,$date,$time "From: myemail\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) {
         
    //clear the variables
         
    $name='';
         
    $email='';
         
    $date='';
         
    $time='';
         
    $subject='';
         
    $message='';
         echo 
    "response=passed";
        } else {
            echo 
    "response=invalid";
            exit;
        }
        
    ?>

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    php mail function takes arguments
    mail($toaddress,$subject,$message,$headers)
    So you need to somehow add the date/time to the message, like
    Code:
    $message = "On $date $time,
    $name wrote:
    $message";
    Also beware .- including user-provided $email in headers makes this script vulnerable. Imagine some idiot submitting a html form to your php script, with email a multiline (textarea) input, containing
    Code:
    some@add.re.ss
    BCC: user1@hotmail.com, user2@hotmail.com, user3@hotmail.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center