PDA

View Full Version : scripting TEXT INPUT boxes.


sai_digitalle
06-04-2005, 05:57 AM
i have text input boxes and the action script i wrote is very VERY basic- so basic that it only checks to make sure that at least something is entered the field. But i'd like to specify format for each respective field (i.e. phone number should be in the format of ###-###-####, and email i want to make sure it is in the format of name@whatever.com etc, event date fomat as ##/##/####)

for gathering the information:

function sendForm() {
gatherForm.recipient = contactForm.recipient.text;
gatherForm.emailto = "andre@immaculate-imagery.com";
gatherForm.visitor_comments = contactForm.userComments.text;
gatherForm.visitor_name = contactForm.userName.text;
gatherForm.visitor_email = contactForm.userEmail.text;
gatherForm.visitor_primaryphone = contactForm.userPhone.text;
gatherForm.visitor_altphone = contactForm.userAltPhone.text;
gatherForm.visitor_eventdate = contactForm.userEventDate.text;
gatherForm.visitor_areaofinterest = contactForm.userOpitions.text;
gatherForm.send ("/cgi-bin/formmail.cgi", "_blank", "POST");

conditional statements:
// onRelease
this.contactForm.submitBtn.onRelease = function() {
if (contactForm.userName.text == "" || contactForm.userEmail.text == "" || contactForm.userPhone.text == "" || contactForm.userAltPhone.text == "" || contactForm.userEventDate.text == "" || contactForm.userComments.text == "" || contactForm.userOptions.label == "Click here to select a subject." ) {
gotoAndStop("error");
} else {
sendForm();
gotoAndStop("correct");
}

and all this does is make sure they at least enter SOMETHING in the fields. i want to specify the format required for the phone number field, e-mail, event date etc...

thanks everyone!

madgett
06-04-2005, 08:18 PM
You do it basically the same way, except use a function that returns a boolean to the if statement. So you will have a function for every type of check that you are doing.
e.g:
// onRelease
this.contactForm.submitBtn.onRelease = function() {
if (contactform(contactForm.userName.text) || contactemail(contactForm.userEmail.text) /* etc... */ ) {
gotoAndStop("error");
} else {
sendForm();
gotoAndStop("correct");
}
};
// You need return statements for when you find a violation, if you don't find a violation then return true
function contactform(t:String):Boolean {
// Username length restrictions
if (t.length == 0 || t.length > 100) {
return false;
} else if (t.indexOf("usernametaken", 0) != -1) { // Username already taken example
return false;
} else { // etc...
return true; // everything is ok
}
}
function contactemail(t:String):Boolean {
// check email...
return true;
}