Results 1 to 5 of 5

Thread: contact form passing variables

  1. #1
    Join Date
    May 2007
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default contact form passing variables

    Hi, I have a contact form, which is a mc (called formMC), and inside I have another mc(called sendMC) to use as the submit button, inside sendMC I have the hit button, which has the code:
    Code:
    on (rollOver) {
    	gotoAndPlay("s1");
    }
    on (releaseOutside, rollOut) {
    	gotoAndPlay("s2");
    }
    on (release) {
    	if (_root.contact_form.t2 eq "" or _root.contact_form.t4 eq "" or _root.contact_form.t5 eq "") {
    		stop ();
    	} else {
    		loadVariablesNum ("submit.php", 0, "POST");
    		//trace ("test");
    		_root.contact_form.gotoAndStop(2);
    	}
    }
    and submit.php is simple (I defined the var as name, message, etc):
    Code:
       $to = "webmaster@1000knots.net";
       $msg = "$name\n\n";
       $msg .= "$message\n\n";
    
      mail($to, $subject, $msg);
    But my problem is that: I can get email, but no POST variables (name. message, etc).

    If I just use a button inside formMC, that works, but I have the button inside another MC, is anything I missed?

    Thanks for the help.

    PS: just thought I should call the parent loadVariablesNum, I am pretty new to actionscript, how can I do that?

    Also I am confused about the level (0) parameter in the loadVariablesNum function, can someone educate me on that?
    Last edited by xxlfm; 06-05-2007 at 12:34 AM. Reason: edit

  2. #2
    Join Date
    May 2007
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help!

    This should be a easy fix, but I dont know how to get the vars form the parent level, then I did something stupid like the following:

    Code:
    on (release) {
    	if (_root.contact_form.t2 eq "" or _root.contact_form.t4 eq "" or _root.contact_form.t5 eq "") {
    		stop ();
    	} else {
    		name = _root.contact_form.t2.text;
    		message = _root.contact_form.t4.text;		
    loadVariablesNum ("submit.php?t2_2=" + name + "&t4_2=" + message, 0, "GET");
    		//trace ("test");
    		_root.contact_form.gotoAndStop(2);
    	}
    }
    It's working, I captured the vars from the parent and use GET, but there must be the way to just use POST to get all the vars.

    Here is submit.php:
    Code:
     $to = "webmaster@1000knots.net";
       $subject = "Web Contact form";
       $headers="From: webmaster<webmaster@1000knots.net>\r\n";
       $headers.='Content-type: text/html';
       $msg = "$t2_2\n\n";
       $msg .= "$t4_2\n\n";
    
      mail($to, $subject, $msg, $headers);
    I will Google and if anyone knows, please help me.

    Thanks.
    Last edited by xxlfm; 06-05-2007 at 09:21 PM.

  3. #3
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    I'm a little confused about your problem (didn't really read very carefully).

    But one thing that I would like to advise you about:
    NEVER USE _root!

    It's a horrible practice. As you get more and more advanced, you'll realize why. Rather use _parent.

    In AS 3.0 _root is deprecated anyway so might as well get used to not knowing it.

    _parent works as such.

    If you are calling a root element from inside a MC (i.e. following heirarchy: root MC >> MC2) you would use this._parent to refer to root MC.

    root MC >> MC2 >> MC3:
    this._parent = MC2
    this._parent._parent = root MC

    and so forth!

  4. #4
    Join Date
    May 2007
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thanks!

    thanks for your great tips! Medyman!

    I found a great tutorial at http://www.nunomira.com/tutorials/loading_variables.php.

    but I am still confused with the level thing:

    so _level0 is root? Can you give me some example?

    Thanks again!

    Also I update my code as th efollwoing, it's cool!

    Code:
    on (release) {
    	if (_parent.t2 eq "" or _parent.t4 eq "" or _parent.t5 eq "") {
    		stop ();
    	} else {
    		varSender = new LoadVars();
    		// create the object to get all the form inputs
    		varSender.t2_2 = _parent.t2.text;
    		varSender.t4_2 = _parent.t4.text;
    		varSender.t5_2 = _parent.t5.text;
    		varSender.send("http://www.ac.net/rvh/submit.php", "_blank", "POST"); 
    		//loadVariablesNum ("http://ac.net/rvh/submit.php?t2_2=" + name + "&t4_2=" + message, 0, "GET");
    		//trace ("test");
    		_parent.gotoAndStop(2);
    	}
    Last edited by xxlfm; 06-07-2007 at 11:10 PM.

  5. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    yes, level0 is the root...

    so if you have a movieclip called MC1 you could call it

    _root.MC1 (a no no!) or _level0.MC1

    they both refer to the same thing but the level 0 is more definite.

    It all depends on the complexity of the flash site you're constructing. The most effective flash sites won't just be one single .swf.

    The simplest circumstance of this will be having a website with 5 pages and each page is an external .swf that will be loaded on runtime. If someone goes to your site for a specific reason, there really is no point in loading the entire site if the user will never visit, right?

    Anyway, so in these external .swfs you might have things in it's root timeline that you're calling with _root. This works when you test the file itself. But when you load it into the larger site .swf, it doesn't. Why? Because _root now refers to _level 0 of the entire movie which would be the larger site .swf.

    So to keep track of where you are in the movie, use _parent.

    If you're not sure where you are, simple use this code:
    Code:
    trace(this)
    ...the output will declare the depth of the MC

Bookmarks

Posting Permissions

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