Current location: Hot Scripts Forums » Programming Languages » PHP » verify form fields.


verify form fields.

Reply
  #21 (permalink)  
Old 05-16-06, 04:49 PM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
i dont know nothin happend it sent the email as always, but no redirect. ill work on it later. thankx for the help though
Reply With Quote
  #22 (permalink)  
Old 05-16-06, 05:30 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
You can try the following as well -
PHP Code:

echo '<meta http-equiv="refresh" content="0;url=thankyou.php">'
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #23 (permalink)  
Old 05-16-06, 08:23 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
hmmm

the way i do it is...

if(!$name){ echo"No name!"; }
if(!$phone){ echo"No NuMBER!";}
and so on...

i think you get the idea...
Reply With Quote
  #24 (permalink)  
Old 05-16-06, 11:16 PM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
mab thats a good idea, ill try that first thing in the morning. i bet that has the best tiem of working. good idea. ill post what happens, along withthe correct script if it works. thanks everyone.
Reply With Quote
  #25 (permalink)  
Old 05-17-06, 09:06 AM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
so thank you to everyone who help this was a great learning experiance.
here is the final output for the php and what needs to be done.
PHP Code:

<?php

                
                        
if (isset($_POST["submit"]))
                        {
                            
$error = array();
                            
$message "";
                            
                            if (
$_POST["abb"] == "")
                            {
                                
$error[] = 'Name field incomplete.';
                            }
                            if (
$_POST["abb1"] == "")
                            {
                                
$error[] = 'Email field incomplete.';
                            }
                            if (
$_POST["abb2"] == "")
                            {
                                
$error[] = 'Street field incomplete.';
                            }
                             if (
$_POST["abb3"] == "")
                            {
                                
$error[] = 'City field incomplete.';
                            }
                            if (
$_POST["abb5"] == "")
                            {
                                
$error[] = 'Zip Coad field incomplete.';
                            }
                           
                             if (
count($error) == 0)
                            {
                                  require 
'abbContact.php';
                                  print 
'<meta http-equiv="refresh" content="0;url=thankyou.php">';
                                  exit;  
                                  
                            }  
                                                        
                        }
                   
?>
you need the exit in there because other wise it stutter steps the refresh. and you need the refresh becasue when you have the
if(count($error) == 0)
{ require 'bla bla.x';
acording to what i researched it returns anything after that to be false. but because of the emta code, refresh which mab helped with it reshes the page and since your data is there is says go to x page.
good job everyone, this was a great help.
Reply With Quote
  #26 (permalink)  
Old 05-17-06, 11:12 AM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by pkcidstudio
PHP Code:

<?php

                
                        
if (isset($_POST["submit"]))
                        {
                            
$error = array();
                            
$message "";
                            
                            if (
$_POST["abb"] == "")
                            {
                                
$error[] = 'Name field incomplete.';
                            }
                            if (
$_POST["abb1"] == "")
                            {
                                
$error[] = 'Email field incomplete.';
                            }
                            if (
$_POST["abb2"] == "")
                            {
                                
$error[] = 'Street field incomplete.';
                            }
                             if (
$_POST["abb3"] == "")
                            {
                                
$error[] = 'City field incomplete.';
                            }
                            if (
$_POST["abb5"] == "")
                            {
                                
$error[] = 'Zip Coad field incomplete.';
                            }
                           
                             if (
count($error) == 0)
                            {
                                  require 
'abbContact.php';
                                  print 
'<meta http-equiv="refresh" content="0;url=thankyou.php">';
                                  exit;  
                                  
                            }  
                                                        
                        }
                   
?>
you need the exit in there because other wise it stutter steps the refresh. and you need the refresh becasue when you have the
if(count($error) == 0)
{ require 'bla bla.x';
acording to what i researched it returns anything after that to be false. but because of the emta code, refresh which mab helped with it reshes the page and since your data is there is says go to x page.
good job everyone, this was a great help.
what if we took this validation a step further for everyone. to the point of checking to make sure the email address was correct. and that the zip code field had 5 numbers in it. here is a validation i have already, if any one is bored and wants to apply it to the above script and apply this validation to it we could help everyone who views this even more and then send people to this for a full validation. here is the script.
PHP Code:

<?php 


Function validate_state_zip(&$state$zipcode) {
    
$state trim($state);
    If (
$state) {
        
$state strtoupper($state);
        If (!
ereg("[A-Z]{2}"$state)) {
            
$error_message "Invalid state";
        }
        ELSE {
            If (
$zipcode) {
                If (
ereg("(AB|BC|MB|NB|NL|NT|NS|NU|ON|PE|QC|SK|YT)"$state)) {    
                    If (!
ereg("^([a-zA-Z0-9]{3} [a-zA-Z0-9]{3})$"$zipcode)) {
                        
$error_message "Invalid Candadian zip code";
                    }
                }
                ELSE {
                    If (!
ereg("(^([0-9]{5})$|^([0-9]{5}-[0-9]{4})$)"$zipcode)) {
                        
$error_message "Invalid U.S. zip code"
                    }
                }
            }
        }
    }
    ELSE {
        If (
$zipcode) {
            
$error_message "State required for zip code"
        }
    }
    return 
$error_message;
}

Function 
validate_phone(&$phone_area, &$phone_local) {
    
$phone_area trim($phone_area);
    
$phone_local trim($phone_local);
    If (
$phone_local) {
        If (!
ereg("^[2-9]{1}[0-9]{2}$"$phone_area) OR !ereg("^([2-9]{1}[0-9]{2}-[0-9]{4})"$phone_local)) {
            
$error_message "Invalid phone number";
        }
    }
    return 
$error_message;
}

Function 
validate_email(&$email) {
    
$email trim($email);
    If (
$email) {
        
$email strtolower(trim($email));
//        If (!ereg("^[._a-zA-Z0-9-]+@[._a-zA-Z0-9-]+\.(com|net|org|edu|mil|gov|gob|info|tv|biz)+(\.[A-Za-z]{2})?$", $email)) {    
        
If (!ereg("^[._a-zA-Z0-9-]+@[._a-zA-Z0-9-]+$"$email)) {    
            
$error_message "Invalid email address";
        }
    }
    return 
$error_message;
}
?>
Reply With Quote
  #27 (permalink)  
Old 05-17-06, 01:00 PM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
done! hope this helps people.
form is now validated. of cource you can go more complex. but this would be all you would need
PHP Code:

<?php

                    
                        
if (isset($_POST["submit"]))
                        {
                            
$error = array();
                            
$message "";
                            
                            if (!
ereg("^[a-z]*$"$name))
                            {
                                
$error[] = 'Name field can only be alphabetic.';
                            }
                            if (!
ereg("^[._a-zA-Z0-9-]+@[._a-zA-Z0-9-]+$"$email))
                            {
                                
$error[] = 'Email field incomplete.';
                            }
                                
                            if (
$_POST["abb2"] == "")
                            {
                                
$error[] = 'Street field incomplete.';
                            }
                             if (
$_POST["abb3"] == "")
                            {
                                
$error[] = 'City field incomplete.';
                            }
                            if (!
ereg("^([0-9]{4,5})$"$zip))
                            {
                                
$error[] = 'Zip Coad field must be 4 to 5 digits in length.';
                            }
                                                       
                             if (
count($error) == 0)
                            {
                                  require 
'abbContact.php';
                                  print 
'<meta http-equiv="refresh" content="0;url=thankyou.php">';
                                  exit;  
                                  
                            }  
                                                        
                        }
                   
?>
Reply With Quote
  #28 (permalink)  
Old 05-19-06, 11:21 AM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
sorry folks, this is much better it really validates it.
PHP Code:

                <?php

                    
                        
if (isset($_POST["submit"]))
                        {
                            
$error = array();
                            
$message "";
                            
$validEmail "^[0-9a-z~!#$%$_-]([.]?[0-9a-z~!#$%$_-])*" "@[0-9a-z~!#$%$_-]([.]?[0-9a-z~!#$%$_-])*" ".[0-9a-z~!#$%$_-]{2,4}([.]?[0-9a-z~!#$%$_-])*$";
                            
$validName "^[a-z]*" " [a-z]*$";
                            
$validZip "^([0-9]{4,5})$";
                            
                            if (!
eregi($validName$_POST["abb"]))
                            {
                                
$error[] = 'Name field incomplete, First and Last Please.';
                            }
                            if (!
eregi($validEmail$_POST["abb1"]))
                            {
                                
$error[] = 'Email field incomplete.';
                            }
                                
                            if (
$_POST["abb2"] == "")
                            {
                                
$error[] = 'Street field incomplete.';
                            }
                             if (
$_POST["abb3"] == "")
                            {
                                
$error[] = 'City field incomplete.';
                            }
                            if (!
eregi($validZip$_POST["abb5"]))
                            {
                                
$error[] = 'Zip Coad field must be 4 to 5 digits in length.';
                            }
                                                       
                             if (
count($error) == 0)
                            {
                                  require 
'abbContact.php';
                                  print 
'<meta http-equiv="refresh" content="0;url=thankyou.php">';
                                  exit;  
                                  
                            }  
                                                        
                        }
                   
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP... PHP form with required fields websearch Job Offers & Assistance 2 04-02-06 11:31 AM
How to make read-only form fields Ashantai JavaScript 4 02-15-05 04:26 PM
lock form fields using checkbox jonathen JavaScript 5 02-04-05 03:35 PM
formmail problem gscraper Perl 12 08-27-04 03:06 AM
displaying fields on the same form aliasgar ASP 1 01-22-04 12:50 PM


All times are GMT -5. The time now is 07:06 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.