I’ve created a flash form using Flash MX 2004. The form consists of testboxes, checkboxes and drop down comboboxes. When you fill out the form, its supposed to send all the data to my PHP page which in turn emails it to me. The only problem is that I’m only receiving the data from the text boxes. How do i get the data from the checkboxes and comboboxes? Is there some sort of actionscripting that needs to be done? I know with the text boxes i declared vars for each box but i cant do that with the other items. Thanks in advance for your help.
You need to store the data you wish to send in your send object (LoadVars or XML, I suppose you’re using LoadVars here), otherwise it will not be sent to the PHP script. So simply add the value of the textbox as a property of the send object and you should be fine.
Using comboboxes and the like is a bit more complicated than just typing a variable for a textboxes. You have to use actionscript to access the selected item in a combobox, and of course your comboboxes all have to have instance names. For example …
my_cb.selectedItem();
… returns the currently selected value of a combobox called my_cb, so you could use the following actionscript to fill up a variable called country_txt with the selected value of the combobox:
var country_txt:String=my_cb.selectedItem();
I suggest you look through the methods and properties of the combobox component in the Flash help files, theres lots there to get your teeth into!
Jed
Can you give a more detailed response with code and where i need to place this actioscript? I’m using a POST method to send the var’s from the text to PHP and i’d like to use the same type of method. Thanks!
The reason you’re only receiving data from the text boxes is because text boxes are the only component to which you can automatically assign a variable in the authoring environment. I gather that you’ve given each of your text boxes a variable but you havn’t done so for your other components. The only data that is sent from your POST method is variables that exist in the current level (or movieclip). This means you’ve got to get the data out of the comboboxes and checkboxes and into variables before you POST to your script. You need to do this after the form has been filled in but before you POST, so the ActionScript to make the variables has to be on the timeline after the form has been completed, or perhaps inside the button you use to execute the POST instruction. So, to make a variable from the selected option on a combobox called my_cb:
var my_variable = my_cb.selectedItem().label;
Make sure the code to make all your variables is placed somewhere where it executes after the form has been filled in but before you POST … good luck!
ok i named all my checkboxes and comboboxes in the instance name. This is my code for the submit button. it still is not working, im only receiving the textbox information:
on (release) {
var Weeks = week.selectedItem().label;
var Case = casetype.selectedItem().label;
var CD = cdtype.selectedItem().label;
var Panels = panel.selectedItem().label;
var Checks1 = check1.selectedItem().label;
var Checks2 = check2.selectedItem().label;
var Checks3 = check3.selectedItem().label;
var Checks4 = check4.selectedItem().label;
form.loadVariables("email.php", "POST");
}
Im not sure if the variables have to be on a different command or if putting them before the post is good enough. Any help would be great. Thanks again
Hey Jarak
A couple of things you could try:
- I just looked at some of my own code, and it seems you might not need the brackets, sorry about that. The syntax should be like this:
var CD = cdtype.selectedItem.label;
- But in order for the above line to work you have to have labels defined on your combobox. Labels are the options you see on the combobox, whereas “data” is what the actual values of those options are. If you just want to send the label to your PHP script the above line should be fine, or else you could send the data by writing this instead (set the labels and data values from the authoring environment):
var CD = cdtype.selectedItem.data;
-
You need to make sure you defining these variables in the same place as your sending them from … do you know what I mean? Its no good defining them all from inside one movieclip and then doing the loadVariables in another movieclip, because your variables wont exist there. Make sure that when you define your variables they are being defined from inside the same movieclip as your comboboxes, and that the comboboxes still exist on the screen … make sure you do the loadVariables command from inside the same movieclip too. It shouldn’t matter if you define the variables just before the loadVariables command as in your example.
-
Checkboxes are different to comboboxes, I’ve never used them before so there might be a different method of getting at their data. I think you have to check whether each one is selected before you make a variable, for example:
if ( my_checkbox.selected==true ) {
var Checks1 = check1.label;
} else {
var Checks1 = “no”;
}
What I’m telling might not be the best way to do this, but its worked for me in the past!
I’m sorry jed. There’s gotta be something im doing wrong thats not allowing me to pass the data from the comboboxes. could you or anyone for that matter mind taking a look at my code and let me know what ive done wrong? please feel free to email me. Thanks!