dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Email contact form "undefined" problem with php

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    129

    Email contact form "undefined" problem with php

    Hello,

    I've made a contact form (well, it's more of a registration form, but that's beside the point) in Flash, and it uses a PHP file to handle the sending.

    I'm receiving the e-mails when I test it, but each field that the user has entered in comes up as "undefined". Can anyone help me with this one?

    Here's the Actionscript for the frame of the contact form:

    Code:
    //	add the listener to the Key onj
    k = new Object();
    k.onKeyUp = function()
    {
    	if(username.text != '' 
    	   && firstname.text != '' 
    	   && surname.text != '' 
    	   && gender.text != ''
    	   && dd.text != 'DD'
    	   && mm.text != 'MM'
    	   && yyyy.text != 'YYYY'
    	   && email.text != ''
    	   && address.text != ''
    	   && postcode.text != ''
    	   && mobile.text != '')
    	{
    		//	enable btn
    		sendMC.sendButton.enabled = true;
    	} else {
    		//	disable
    		sendMC.sendButton.enabled = false;
    	}
    }
    Key.addListener(k);
    
    //	set starting status
    //	for SEND button
    sendMC.sendButton.enabled = false;
    // stop on current frame
    stop();
    And the code for the SUBMIT button:

    Code:
    on (release) {
    	//	Now import the variables we
    	//	need to send in this movie clip
    	sender_username = this._parent.username.text;
    	sender_firstname = this._parent.firstname.text;
    	sender_surname = this._parent.surname.text;
    	sender_gender = this._parent.gender.text;
    	sender_dd = this._parent.dd.text;
    	sender_mm = this._parent.mm.text;
    	sender_yyyy = this._parent.yyyy.text;
    	sender_email = this._parent.email.text;
    	sender_address = this._parent.address.text;
    	sender_postcode = this._parent.postcode.text;
    	sender_mobile = this._parent.mobile.text;
    	//	all the vars we just imported
    	//	will be sent via POST method now
    	loadVariables("register.php", this, "POST");
    	//	and when receives the answer from
    	//	the server...
    	this.onData = function()
    	{
    		for(var a in this) 			trace([a,this[a]])
    				//	ok, next frame
    		this._parent.nextFrame();
    		if(this.output=='sent')
    		{
    			// in case of success
    			this._parent.errTitle = 'Thank you for your application.';
    			this._parent.errType = "Our administration will verify your details and send you an email to confirm the outcome.";
    		} else {
    			//	else
    			this._parent.errTitle = "Error!";
    			this._parent.errType = "The application could not be processed correctly. Please give time for our administration to solve the problem, and then try again later.";
    		}
    	}
    }
    And finally, the PHP code:
    PHP Code:
    <?
    if(!empty($HTTP_POST_VARS['sender_username']) || !empty($HTTP_POST_VARS['sender_firstname']) || !empty($HTTP_POST_VARS['sender_surname']) || !empty($HTTP_POST_VARS['sender_gender']) || !empty($HTTP_POST_VARS['sender_dd']) || !empty($HTTP_POST_VARS['sender_mm']) || !empty($HTTP_POST_VARS['sender_yyyy']) || !empty($HTTP_POST_VARS['sender_email']) || !empty($HTTP_POST_VARS['sender_address']) || !empty($HTTP_POST_VARS['sender_postcode']) || !empty($HTTP_POST_VARS['sender_mobile']))
    {
        
    $to "chris@broken-designs.com";
        
    $subject "A new Street Team member has registered";
        
    $body .= "Username: " $HTTP_POST_VARS['sender_username'] . "\n";
        
    $body .= "First name: " $HTTP_POST_VARS['sender_firstname'] . "\n";
        
    $body .= "Surname: " $HTTP_POST_VARS['sender_surname'] . "\n";
        
    $body .= "Gender: " $HTTP_POST_VARS['sender_gender'] . "\n";
        
    $body .= "Date of Birth: " $HTTP_POST_VARS['sender_dd'] . "/" $HTTP_POST_VARS['sender_mm'] .    "/" $HTTP_POST_VARS['sender_yyyy'] . "\n";
        
    $body .= "Email: " $HTTP_POST_VARS['sender_email'] . "\n";
        
    $body .= "Address line 1: " $HTTP_POST_VARS['sender_address'] . "\n";
        
    $body .= "Post Code: " $HTTP_POST_VARS['sender_postcode'] . "\n";
        
    $body .= "Mobile no: " $HTTP_POST_VARS['sender_mobile'] . "\n";
        
    $body .= "Please verify that all the above details are correct and that the Username is unique. If so, add them to the member list and e-mail them their password. If not, please send them an e-mail asking them to change the incorrect details.";
        
    $header "From: " $HTTP_POST_VARS['sender_username'] . " <" $HTTP_POST_VARS['sender_email'] . ">\n";
        
    $header .= "Reply-To: " $HTTP_POST_VARS['sender_username'] . " <" $HTTP_POST_VARS['sender_email'] . ">\n";
        
    $header .= "X-Mailer: PHP/" phpversion() . "\n";
        
    $header .= "X-Priority: 1";
        if(@
    mail($to$subject$body$header))
        {
            echo 
    "output=sent";
        } else {
            echo 
    "output=error";
        }
    } else {
        echo 
    "output=error";
    }
    ?>
    Anyone know where I've gone wrong? Thanks.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    first step - check the variables with a trace action

    on (release) {
    sender_username = this._parent.username.text;
    trace(sender_username ); // what is the output ??
    //... repeat for the other variables
    //....
    }

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Alright, I did that, and it worked... Would that have really solved it?

    I also noticed that I had "/n" written for new lines in my PHP coding instead of "\n". Would that have been the problem?

    Oh... and thanks for your fast response and help, very hard to come by these days!

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    not sure about /n versus \n ?
    you could always echo the received vars from php to verify if received correctly

  5. #5
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Whilst I'm here, is it possible I could have a bit of assistance with a different bit of scripting?

    Once the members are signed up I'll have their basic details stored in a txt file like this:

    Code:
    memberData=User1,password1,emailaddress@hotmail.com
    User2,password2,emailaddress2@hotmail.com
    On the opening frame of the Flash movie, there's this code:
    Code:
    var memberData = this.loadVariables("members.txt", 0);
    Then at the login screen frame:
    Code:
    stop();
    memberData = memberData.split('\n');
    // initialize stuff...
    var success = false;
    var totalMembers = memberData.length;
    var memberArray = new Array();
    for (var ndx = 0; ndx<totalMembers; ++ndx) {
    	memberArray.push(memberData[ndx].split(','));
    	_root.newest=memberArray[ndx][0];
    }
    _root.total=totalMembers;
    And the LOGIN button code:
    Code:
    on (release, keyPress "<Enter>") {
    	user=user;
    	for (var ndx = 0; ndx<totalMembers; ++ndx) {
    		if (user == memberArray[ndx][0]) {
    			if (pass == memberArray[ndx][1]) {
    				gotoAndStop("Website", 1);
    				success = true;
    				youremail=memberArray[ndx][2];
    				password=memberArray[ndx][1];
    				Submit = "Yes";
    			}
    		}
    		if (false == success) {
    			gotoAndStop(3);
    			error = "Login details incorrect. Please try again.";
    		}
    	}
    }
    This works when I test it on my PC, but as soon as I upload it and try it on the server, it just doesn't do anything. What's more, the "Newest member" box says "Undefined." Where is this going wrong?

    And finally, a bit of advice please.
    On that text file of the members with their username and password, I'd also like to assign an access level to each member. There'll be 10 different permission levels, 1 being the lowest and 10 being the heighest. How would I write these levels into the text file, and how would I call this into the flash file?

    I take it then it's just a simple case of adding this actionscript once that's done:
    Code:
    if (userlevel < 5) {
    	setProperty(secretcontent, _visible, "0");
    }
    Thanks in advance.

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    upload it and try it on the server, it just doesn't do anything.

    could be due to server lag and the use of loadVariables
    recommend you use a LoadVars object instead
    plenty of examples by searching this forum or Adobe.com or Google

    write these levels into the text file
    something like -
    memberData=User1,password1,emailaddress@hotmail.co m,5

    how would I call this into the flash file
    something like -
    _root.userlevel=memberArray[ndx][3];
    if (userlevel < 5) secretcontent._visible = 0;

  7. #7
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Will this entail me having to rewrite the code? Or do I just replace "loadVariables" with "LoadVars"?

    If it's the first one, is there any way you could point me in the right direction? To be honest I wouldn't even know where to start looking...

  8. #8
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    this Sticky is a good starting point

    I can see vars in a textbox, but my script does not work?
    http://board.flashkit.com/board/showthread.php?t=394127

  9. #9
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Whoops, that thread went way over my head
    Is anyone here able to adjust my code to the correct way of doing it for me please?
    I'd be eternally grateful.

  10. #10
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    add a final variable to your text file (eof - note use of &)

    memberData=User1,password1,emailaddress@hotmail.co m
    User2,password2,emailaddress2@hotmail.com&
    &eof=yes&

    in Flash, loop around frames 2&3 until the eof is received -
    frame1 -
    var memberData = this.loadVariables("members.txt", 0);
    frame2 -
    blank
    frame3 -
    if(eof=="yes"){
    gotoAndStop(4);
    } else {
    gotoAndPlay(2);
    }
    frame4 - all loaded, use the variables

    hth

  11. #11
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Worked an absolute treat! Way to go. I'm new to the coding side of design so I can't think of ways around problems yet. I really appreciate your help.

    For bonus points, wanna help me solve the last piece of the puzzle?

    I'm trying to get the Userlevels to work, but it doesn't seem to. Regardless of the user level, users can access anything, despite the restrictions.

    Here's the code I've put on a "special area" button for users only level 5 and above:

    Code:
    on (release) {
    	_root.userlevel=memberArray[ndx][3];
    	if (userlevel >= 5) {
    		tellTarget (this.pages) {
    			gotoAndStop("special");
    		}
    	}
    	
    }
    It seems alright to me... have I done something wrong?

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    1 - use a trace to see if your variable is correct
    2 - use dot syntax - tellTarget is deprecated
    3 - use the correct path - you have _root.userlevel and yet you check for
    if(userlevel) {.. with no _root prefix..}

    on (release) {
    _root.userlevel=memberArray[ndx][3];

    trace(_root.userlevel); // what is the result ?
    trace(typeof _root.userlevel); // what is the result ?

    if (_root.userlevel >= 5) { pages.gotoAndStop("special"); } // end if
    }

    if the result of typeof = "string", you'll have to use -
    if (_root.userlevel >= "5") {....}

  13. #13
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    They're both coming out as "undefined" with that one!

  14. #14
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try a test button to determine if the path to the array is correct

    on(release){
    trace(ndx); // is this index number viable ?
    trace(memberArray[ndx][3]); // undefined ??
    trace(_root.memberArray[ndx][3]); // what result here with _root.prefix ??
    }

  15. #15
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    I got:

    undefined
    undefined
    2
    undefined
    undefined

    from:

    Code:
    on (release) {
    	_root.userlevel = memberArray[ndx][3];
    	trace(_root.userlevel);
    	// what is the result ?
    	trace(typeof _root.userlevel);
    	// what is the result ?
    	trace(ndx);
    	// is this index number viable ?
    	trace(memberArray[ndx][3]);
    	// undefined ??
    	trace(_root.memberArray[ndx][3]);
    	// what result here with _root.prefix ??
    	if (_root.userlevel>="5") {
    		pages.gotoAndStop("special");
    	}
    	// end if
    }

  16. #16
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try opening the scope of the array

    replace
    var memberArray = new Array();
    with
    _global.memberArray = new Array();

    run the test again

  17. #17
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Hmm sorry... where does that go?

  18. #18
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    in your post at 03:18 PM, you state -

    Then at the login screen frame:

    stop();
    memberData = memberData.split('\n');
    // initialize stuff...
    var success = false;
    var totalMembers = memberData.length;
    // var memberArray = new Array();

    // replace the above with -
    _global.memberArray = new Array();

  19. #19
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Ah thanks...


    Still get:

    undefined
    undefined
    2
    undefined
    undefined


    Hmm!

  20. #20
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    sorry

    at the limit of my help capabilities here

    throw traces at it till it spits out what you require

    good luck

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