I took the simple contact form from Kirupa, and added a couple of features. First I added a bit of simple validation to the Name, Email, and Message fields, to ensure that these values are supplied. After testing the form, I realized, that if I forgot to enter my email, received an error, and then hit the “back” button, I lost my entered information, which in the case of a long message, would be pretty devastating. SO, I set up some global variables that store the value of the form in the case of an error, and place it back in the form when you return to add the details you missed. What I created is essentially just a Flash version of the Sticky Form. If you wish for the PHP to work, you must enter your own email address in the source. This form is currently functioning perfectly on my employer’s website, arrco.com
Feel free to pick apart my Source files, and use this form on your page.
EDIT: I just revised my conditional for the validation, to ensure that there is a character in each box, and specifically for email, that there is an @ symbol at an index higher than zero, this ensures that a valid email address has been entered, or at least faked. I have not revised my attachment to this effect, so it will have to be done manually if you wish to use it.
NEW CONDITIONAL:
if (formName.charAt(0) && formEmail.indexOf("@") > 0 && formMessage.charAt(0))
I haven’t looked at your code yet, but what I do is use sendAndLoad for transmitting the information to a PHP script. The script does the validation (I can give you a regex expression for checking valid emails if you need it), and then it sends a response back to the PHP form (You missed some fields, your email is invalid, message submitted successfully, etc) and the flash form displays the message without any actual page changes. This way, if an error, the content stays in the boxes.
I actually had to do a presentation on this topic at a work meeting. I have attached the notes and the code and swf to this reply. Please let me know if I can help with anything.
[quote=djheru;2325258]I haven’t looked at your code yet, but what I do is use sendAndLoad for transmitting the information to a PHP script. The script does the validation (I can give you a regex expression for checking valid emails if you need it), and then it sends a response back to the PHP form (You missed some fields, your email is invalid, message submitted successfully, etc) and the flash form displays the message without any actual page changes. This way, if an error, the content stays in the boxes.
I actually had to do a presentation on this topic at a work meeting. I have attached the notes and the code and swf to this reply. Please let me know if I can help with anything.[/quote]
I actually wrote my own script to make the forms “sticky”. This preserves the text entered in the case of an error. Of course flash would have a built-in function that does this… My conditional is pretty simple, and it at least checks that the email has an “@” symbol, something that all emails must have. I am sure the built-in function has some serious validation, but this suits the low-profile contact form I use it for, but please share anything you have that is better, because I am more of a designer and less a programmer, and am always looking for ways to make the programming easier.
Hi! Thanks very much for this, saved me a bunch of mucking around!
I’ve used it on my site (www.joshcaple.com) & it emails me fine but the validation/error msg doesn’t seem to work? Can anyone help me out?
(link removed)
I’d also like to make it so that when the user first clicks on the field, the words are already highlighted (to delete them more easily, a pedantic touch :P)
[quote=joshcaple;2328670]Hi! Thanks very much for this, saved me a bunch of mucking around!
I’ve used it on my site (www.joshcaple.com) & it emails me fine but the validation/error msg doesn’t seem to work? Can anyone help me out?
I’d also like to make it so that when the user first clicks on the field, the words are already highlighted (to delete them more easily, a pedantic touch :P)[/quote]
Hmmm… I can’t open your file, because it is probably saved in CS3 and I have Flash 8. I can only guess that the validation isn’t working because you used my original conditional which checks only that the form values are not “undefined”. Since the default text is set, your validation is not working. I didn’t take default text into account when I created the form. As far as the text being removed/selected on focus, use this script within the input text field clip.
name_txt.onSetFocus = function (){
if (name_txt.text == "Name") {
name_txt.text = "";
}
}
company_txt.onSetFocus = function (){
if (company_txt.text == "Company") {
company_txt.text = "";
}
}
email_txt.onSetFocus = function (){
if (email_txt.text == "Email") {
email_txt.text = "";
}
}
message_txt.onSetFocus = function (){
if (message_txt.text == "Message") {
message_txt.text = "";
}
}
That should replace all the text with nothing when the user focuses on the textfields. Also, be sure to replace the conditional within the submit button script with the below conditional.
[quote=joshcaple;2328739]Thanks very much, works perfectly now!!
The one mod I would like like to make is to have the default text reappear if they don’t type anything in the box… any ideas?[/quote]
You and your “mods” hahaha. The only thing wrong with that is that it would cause the text to validate if the person never ends up entering anything, unless of course you modify the conditional AGAIN to kick back entries of the default text. hahahah. I guess this is how we learn more every day.
Add below script to the onSetFocus script within field clip
name_txt.onKillFocus = function (){
if (name_txt.text == "") {
name_txt.text = "Name";
}
}
company_txt.onKillFocus = function (){
if (company_txt.text == "") {
company_txt.text = "Company";
}
}
email_txt.onKillFocus = function (){
if (email_txt.text == "") {
email_txt.text = "Email";
}
}
message_txt.onKillFocus = function (){
if (message_txt.text == "") {
message_txt.text = "Message";
}
}
And here is your shiny new conditional which now spans multiple lines thanks to your dubious desires of intuitive functionality: