Hello!
For the past few days I’ve been trying to set up a flash form which will take a visitor’s details and then write them to a database. Looking at all the tutorials I thought it was going to be easy, although now a couple of days down the line, I regret thinking that.
Basically I’ve followed this tutorial many times and couldn’t get it to work. I presumed my server doesn’t support asp. How do I check if it does?
Anyway, after this I followed a php to txt file tutorial which I forget the address of now, checking it against this one to see if I was doing it correctly. I know that’s a form variables to email tutorial but I changed the email to make it write to a text file. This would take the variables from the form and the php would write it to a txt file. OK. So I couldn’t get that to work either. Here’s what I’ve got so far:
A flash form shown online here.
The flash actionscript is as follows:
In frame1:
formData = new LoadVars();
function checkValues() {
formData.bday1 = bdaybox1.selectedItem.label;
formData.bday2 = bdaybox2.selectedItem.label;
formData.bday3 = bdaybox3.selectedItem.label;
formData.gender = genderRadio.selection.label;
formData.name = name_txt.text;
formData.surname = surname_txt.text;
formData.address1 = address1_txt.text;
formData.address2 = address2_txt.text;
formData.address3 = address3_txt.text;
formData.address4 = address4_txt.text;
formData.postcode = postcode_txt.text;
formData.email = email_txt.text;
formData.mobile = mobile_txt.text;
formData.referer = referer_txt.text;
}
On the submit button:
on (press) {
checkValues ()
formData.sendAndLoad("processForm.php", formData, "POST");
formData.onLoad = function(ok) {
if (ok) {
trace("Data saved");
}
};
}
I’ve used the flash debugger and the variables are in place and I think this is all working ok.
The php script is as follows:
<?php
//Capture data from $_POST array
$name = $_POST['name'];
$surname = $_POST['surname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$postcode = $_POST['postcode'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$referer = $_POST['referer'];
$bday1 = $_POST['bday1'];
$bday2 = $_POST['bday2'];
$bday3 = $_POST['bday3'];
$gender = $_POST['gender'];
//Make one big string in a format Flash understand
$toSave ="$name|$surname|$address1|$address2|$address3|$address4|$postcode|$mobile|$email|$referer|$bday1|$bday2|$bday3|$gender";
//Open a file in write mode
$fp = fopen("database.txt", "w");
if(fwrite($fp, $toSave)) echo "writing=Ok&";
else echo "writing=Error&"
fclose($fp);
?>
I’m no newbie to actionscript but have only ever used php for contact form emails. So I’m guessing that’s where my mistake lies. I’ve also tried setting permissions on my web space so everything is writable and executable and all that with no difference.
I’d REALLY appreciate it if anyone can help as I’ve been stuck on this for longer than I can remember being stuck on anything!
Let me know if there’s anything I’ve missed out.
Cheers,
Paul