Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    adding validators to my sendEmail

    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.

    PHP Code:
                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
                        { 
                            
    senderNameSender
                            
    senderEmailEmail
                            
    senderHomePhoneHomePhone
                            
    senderDateDate,
                            
    senderGuestsGuests
                            
    senderSchoolSchool,
                            
    senderTimeTime,
                            
    senderEventEvent,
                            
    senderAboutAbout,
                            
    senderCommentsComments,
                            
    sendTypeType 
                        
    }); 
                }
                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

  • #2
    New Coder
    Join Date
    Jan 2012
    Location
    RI, USA
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <?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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •