...

View Full Version : adding validators to my sendEmail



akuria
01-26-2012, 02:11 AM
so i have a http service sending input fields via php file. i want to make some of the fields required. i have tried a couple different ways and neither have worked.

here is the code i have.


protected function submit_appointment_clickHandler():void
{
var Sender:String = "";
var Email:String = "";
var HomePhone:String = "";
var Date:String = "";
var Guests:String = "";
var School:String = "";
var Comments:String = "";
var Time:String = "";
var Event:String = "";
var About:String = "";
var Type:String = currentState;

switch(currentState)
{
case "home":
Sender = promoFirstName.text + " " + promoLastName.text;
Email = promoEmail.text;
break;
case "Reservation":
Sender = resFirstName.text + " " + resLastName.text;
Email = resEmail.text;
HomePhone = resPhoneNumber.text;
Date = resDate.text;
Guests = resGuests.text;
School = resSchoolName.text;
Time = resTime.selectedItem;
Event = resEvent.selectedItem;
About = resAbout.selectedItem;
Comments = resDescription.text;
break;
}

emailService.send(
{
senderName: Sender,
senderEmail: Email,
senderHomePhone: HomePhone,
senderDate: Date,
senderGuests: Guests,
senderSchool: School,
senderTime: Time,
senderEvent: Event,
senderAbout: About,
senderComments: Comments,
sendType: Type
});
}
private function emailResult():void
{
Alert.show("Thank you for your submission. You will be contacted shortly.");
clearForm();
}
private function clearForm():void
{
promoFirstName.text = "";
promoLastName.text = "";
promoEmail.text = "";

resFirstName.text = "";
resLastName.text = "";
resEmail.text = "";
resPhoneNumber.text = "";
resDate.text = "";
resGuests.text = "";
resSchoolName.text = "";
resDescription.text = "";
resTime.selectedIndex = -1;
resEvent.selectedIndex = -1;
resAbout.selectedIndex = -1;
}

]]>

</fx:Script>
<s:states>
<s:State name="home"/>
<s:State name="ProtegeExperience"/>
<s:State name="ourVenue"/>
<s:State name="imageGallery"/>
<s:State name="Reservation"/>
<s:State name="Events"/>
<s:State name="Contact"/>
<s:State name="ourFans"/>
<s:State name="Pricing"/>
</s:states>
<fx:Declarations>
<s:HTTPService id="emailService"
url="sendEmail.php"
method="POST"
resultFormat="xml"
result="emailResult()"
useProxy="false"/>
</fx:Declarations>

Alternative
01-26-2012, 04:10 PM
<?php
function checkEmail($email) {
$emailParts = explode("@", $email);
$beforeAtSymbol = $emailParts[0];
if (substr_count($emailParts[1], ".") > 2) {
//Too many dots after the @ symbol.
return false;
}

$afterAtSymbol = explode(".", $emailParts[1]);

if ($beforeAtSymbol == "") {
return false;
}

if (sizeof($emailParts) !== 2) {
//You need one and only one @ in the email.
return false;
}

if (strlen($beforeAtSymbol) < 2 || strlen($beforeAtSymbol) > 30) {
//I do not know anybody who has an e-mail that is longer than 30 characters for what is before the @ symbol, or who has an e-mail with only one letter there.
return false;
}

for ($i = 0; $i < sizeof($afterAtSymbol); $i++) {
}
if (sizeof($afterAtSymbol) > 3 || sizeof($afterAtSymbol) == 0) {
return false;
}
if (strlen($afterAtSymbol[0]) > 20 || strlen($afterAtSymbol[0]) < 2) {
return false;
}
if (strlen($afterAtSymbol[1]) > 4 || strlen($afterAtSymbol[2]) > 4) {
//.com, .info, .biz, .us....none of these are more than 4 characters.
return false;
}
return true;
}
?>


E-mail check function. It's certainly not bulletproof, but it's acceptable. Returns false or true. Most of your validations shouldn't be hard....just make sure the name is between 0 and 30 characters, etc.

I will post a phone number validator if I can find it in my files...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum