Jump to content


Photo

Help in Validating Form


  • Please log in to reply
2 replies to this topic

#1 Terfanda

Terfanda
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 19 June 2006 - 07:51 PM

[img src=\"style_emoticons/[#EMO_DIR#]/excl.gif\" style=\"vertical-align:middle\" emoid=\":excl:\" border=\"0\" alt=\"excl.gif\" /]
            function CreateForm()
            {
                
                print("<form action=\"Petition.php\" method=post>\n");
                print("First Name :<input type=text name=\"fname\" size=24 maxlength=32>");
                print(" Last Name  :<input type=text name=\"lname\" size=24 maxlength=32><br>\n");
                print(" Email   :<input type=text name=\"mailaddress\" size=30 maxlength=60><br>\n");
                print("<input type=hidden name=\"BeenSubmitted\" value=\"TRUE\"><br>\n");
                print("<input type=submit name=\"submit\" value=\"Submit\"></form>\n");
            }
            
                    function emailcheck($Email)
                     {
                                 if(!ereg("^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$Email))
                                {
                                    //err.=$Email."is not a valid email address.<br/>";                
                                    $ans=FALSE;
                                }else{
                                 $ans=TRUE;
                                 }
                                return $ans;
                                }
                            
                    
                    
                    function check_forFileds($Name,$FamName,$Email)
                    {
                       if((!$Name)||(!$famName)||(!$Email))
                       {
                             print("Invalid Input\n");
                             $ans=FALSE;
                             }
                             else{
                              $ans=TRUE;
                                  }
                      return $ans;
                    }
                        

            function HandleForm()
            {  
                        
                        $Name=$_POST['fname'];
                        $FamName=$_POST['lname'];
                        $Email=$_POST['mailaddress'];
                        $TheDate=date("j F Y H:i:s");
                        
                        
                            
                             
                                $acc=emailcheck("$Email");
                                 $acc=check_forFileds("$Name","$FamName","$Email");
                                                  
                                                        if ($acc==TRUE)
                                                        {
                                                            $CallFunction=WriteToFile("$Name","$FamName","$Email","$TheDate");
                                                        }
                                                    
                                                            else
                                                                {
                                                                    print("Please enter a valid Input !\n");
                                                                }
                    
                            }       
                            
                                            if(!isset($_POST['BeenSubmitted']))
                                               {
                                                   HandleForm();
                                               }
                                           CreateForm();
               
                ?>



I am new athis when i run it
it is giving me this errors:


Notice: Undefined index: fname in ->$Name=$_POST['fname'];

Notice: Undefined index: lname in ->$FamName=$_POST['lname'];
Notice: Undefined index: mailaddress in ->$Email=$_POST['mailaddress'];
Warning: ereg(): REG_BADRPT in ->if(!ereg("^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$Email))


I Appreciate your help
thank you in advance

EDITED BY WILDTEEN88: PLEASE USE THE CODE TAGS WHEN SUBMITTING BLOCKS OF CODE

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 June 2006 - 07:54 PM

I think this:
if(!isset($_POST['BeenSubmitted']))

should be:
if(isset($_POST['BeenSubmitted']))

As currently it is validating form input when the form hasn't been submitted yet! Thats why you are getting the undefind index notices.

#3 Terfanda

Terfanda
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 19 June 2006 - 08:11 PM

[!--quoteo(post=385783:date=Jun 19 2006, 10:54 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 19 2006, 10:54 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I think this:
if(!isset($_POST['BeenSubmitted']))

should be:
if(isset($_POST['BeenSubmitted']))

As currently it is validating form input when the form hasn't been submitted yet! Thats why you are getting the undefind index notices.
[/quote]


First of al thank you
i did wut you said an i got a new error

Warning: ereg(): REG_BADRPT if(!ereg("^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$Email))


can you please tell me my mistake





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users