The last step in my contact form is taking all of this data that the user enters and then sending it out to an email address. So I'm going to double-click on this Contact movie clip. And as you can see right in here, I have my input text fields, even a feedback text field. And then associated to this button, I have some ActionScript. So let's take a look at that. In this first frame of the Actions layer, I can open up the Actions panel and view all of that code.
So currently, I'm tracing out that data, which means it's just appearing in my Output panel, but what I want to do is I want to take all of this data. And I want to package it up into one variable package. And then send it to a specific URL. So the nice thing is is I can replace these comments with my own comments if I want to. And that's what I want to do right now. I'm going to just create a variable container, okay. And I'll just delete this line real fast.
All right, and this is basically going to be called var. I'm creating a new variable, and it's called allVars. All my variables are going to go in this big box called allVars. It is URLVariables. And as I type in URLV, I can see URLVariables. And it highlights it. I can hit Enter. And it will automatically add that word for me. And I'm basically creating a new URLVariables container URLVariables().
All right, so now what I need it to do is need to copy this. And inside of this Variables container, I need to have it contain the name, which is going to be equal to the text in this instance name field here. So same thing right here, allVars.email, within that Email variable, contains that information. And then message contains any text that's in this instance name field here as well.
Okay, so within this sort of box contains these three variables. All this information gets packed up into this nice little variable container right here. And then what I can do is I can then go ahead and send that information out to a URL. So that's what I'm going to do next. I'm going to create a new URL. Let me just add another comment, so, //Send info to a url. So I'm creating a new variable called mailAddress.
I'm making a URLRequest and again as soon as it highlights it, I can hit enter. And it will add that whole word, new URLRequest. Again, it highlights that line. I can hit Enter. And now I can go ahead and type in the URL that I want this information sent to. In my specific case, it's going to be jillgraphicdesigner.com/gdform.php. So this is basically a PHP page provided by my hosting company, which happens to be Go Daddy.
So they provide me with this PHP page. And this PHP page takes all of that information and sends it out to the email address that I have defined through Go Daddy's control panel. But the point here is you just need to check with your hosting company to see how they deal with PHP forms, because they might have a different name or location for their form.php file, but in general that's where the data is going to be sent. And this is just all through this URLRequest. And what I can do now is I need to make sure I attach that data to that URLRequest.
So I need to say mailAddress. Well, the data for that mailAddress is going to be all my variables. So again, I'm making sure these names match up because it's going to take all this data and attach it to the data property of my mailAddress. Next thing I need to is just go ahead and post that information to the URL mailAddress.method. Again, as soon as the word is highlighted, you can hit Enter, URLRequestMethod.POST because it's going to post this information to this URL, okay.
So that's what it's going to do. It's going to post it there. Okay, so the data is there. It posts it. And that's the sort of the method that it's going to send it. Technically, I need to actually do a sendToURL(mailAddress). So this is technically the final sort of send of all of this information. So I didn't use a Navigate toURL or anything. The nice thing about this chunk of code is that it sends the data behind the scenes if you will, without interrupting your experience.
But again, it seems like a lot of code, but this does all the work sort of behind the scenes. Post that data to the PHP page. And again, notice where I've put it, okay. So I've just started typing it right in here. Well, I mean what if they haven't filled in all of these fields? Well, what I need to do is I need to take all of this information. And I will cut it. And I'm going to put it right in here in this else statement, because I want this to happen, of course, if they have filled in all the fields, then send the data.
Another neat sort of cleanup feature you can do is you can click this sort of fifth button in, the Auto format. If I click that, it will sort of indent everything appropriately. And you can see my large else statement. That really does all of the work if all the fields are filled in. So with that good to go, I can go ahead and do a Test Movie. Go to my Contact page. Enter in my email address, something like that. Send the message.
Click Send. It says thank you! And then if I go to basically my email that I've defined with my hosting provider, I should see that email in my Inbox. Here it is, my Inbox, right here, the email that was sent, my information. And everything is working out just great. So again, that was just a quick example of how to take that information that was in Flash and send it to a PHP page that does most of the work doing the final step of actually sending the email.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Your file was successfully uploaded.