Results 1 to 3 of 3

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Black Hawk's Avatar
    Join Date: Sep:2003
    Location:
    Posts: 871

    PHP/Javascript ( )

    , PHP, .
    Verification Form-a, : , , . "Submit", validateFormOnSubmit(theForm) Java Script . - , alert .
    PHP- -, submit, ( , , : "" ). , , PHP, , , . PHP . ... .
    , HTML/Java, :
    Code:
    <html>
    <head>
      <title>..:: XXX ::..</title>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
      <link rel="stylesheet" type="text/css" href="style.css" />
    
    <script type="text/javascript">
    function validateFormOnSubmit(theForm) {
    var reason = "";
    
    
      reason += validateName(theForm.name);  
      reason += validateChip(theForm.chip);
      reason += validateDay(theForm.day);
      reason += validateMonth(theForm.month);
      reason += validateYear(theForm.year);
     
          
      if (reason != "") {
        alert("Error! The following error occurred during the processing:\n" + reason);
        return false;
      }
    
      alert("Thank you, all of your data were collected successfully!");
      return false;
    }
    function validateDay(fld) {
        var error = "";
     var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');  
    
       if (fld.value == "") {
            error = "You haven't enter a day.\n";
     } else if ((fld.value < 1) || (fld.value > 31)) {
            
            error = "The day cannot exceed values over 31 or be less than 01.\n";
           
        } else if (isNaN(fld.value)) {
            error = "The day field contains illegal characters.\n";
     
        } else if (!(stripped.length == 2)) {
            error = "The day is the wrong length.\n";
            
        }
        return error;
    }
    function validateMonth(fld) {
        var error = "";
     var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');  
    
       if (fld.value == "") {
            error = "You haven't enter a month.\n";
     } else if ((fld.value < 1) || (fld.value > 12)) {
            
            error = "The month cannot exceed values over 12 or be less than 01.\n";
           
        } else if (isNaN(fld.value)) {
            error = "The month field contains illegal characters.\n";
     
        } else if (!(stripped.length == 2)) {
            error = "The month is the wrong length.\n";
            
        }
        return error;
    }
    function validateYear(fld) {
        var error = "";
     var d = new Date();
     var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');  
    
       if (fld.value == "") {
            error = "You haven't enter a year.\n";
     } else if (fld.value < 1980) {
            error = "The year must be greater than 1980\n";
           
        } else if (isNaN(fld.value)) {
            error = "The year field contains illegal characters.\n";
     
        } else if (!(stripped.length == 4)) {
            error = "The year is the wrong length.\n";
      
       
        }
        return error;  
       
    }
    function validateName(fld) {
        var error = "";
        var illegalChars = /[^a-zA-Z]/;
     
     
        if (fld.value == "") {
            
            error = "You haven't enter dog's name.\n";
        } else if ((fld.value.length < 1) || (fld.value.length > 50)) {
            
            error = "Dog's name is the wrong length.\n";
        } else if (illegalChars.test(fld.value)) {
            
            error = "Dog's name contains illegal characters.\n";
           
        }
        return error;
    }
    
    function trim(s)
    {
      return s.replace(/^\s+|\s+$/, '');
    }
    
    function validateChip(fld) {
        var error = "";
        var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');  
    
       if (fld.value == "") {
            error = "You haven't enter a chip's number.\n";
           
        } else if (isNaN(fld.value)) {
            error = "Your chip number contains illegal characters.\n";
           
        } else if (!(stripped.length == 8)) {
            error = "Your chip number is the wrong length. It must be 8 characters\n";
           
        }
        return error;
    }
    </script>
    </head>
    <body>
    <TABLE cellpadding="0" cellspacing="0" border="1" bordercolor="black" align="center">
     <tr>
      <td valign="top" width="874" height="400>
       <table cellpadding="0" cellspacing="0" border="2">
    <strong><center>REGISTER YOUR DOG! </center></strong>
    <form name="cardverif"   onSubmit="return validateFormOnSubmit(this)" action="">
    <table summary="Verification Form">
    <table>
      <tbody>
      <tr>
        <td><label for="name"><strong>ENTER DOG'S NAME:</strong></label></td>
        <td><input name="name" size="41" maxlength="50" type="text"></td>
      </tr>   
    
     
      <tr>
        <td><label for="chip"><strong>ENTER CHIP'S NUMBER:</strong></label></td>
        <td><input name="chip" size="41" maxlength="25" type="text"></td>
      </tr>   
      
      <tr>
        <td><label for="month"><strong>DATE OF BIRTH</strong></label></td>
    	<td width="300">Day: <input name="day" size="2" maxlength="2" type="text"> Month: <input name="month" size="2" maxlength="2" type="text"> Year: <input name="year" size="4" maxlength="4" type="text"></td>
      </tr>
       
     
      <tr>
        <td> </td>
        <td><input name="Submit" value="Submit" type="submit" ></td>
        <td width="135"> </td>
      </tr>
     
      </tbody>
      </table>
      </form>
       </table>
       </td>
      </tr>
    </table>
    </body>
    </html>
    PHP-...
    Code:
    <?php
    error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
    $name = $_POST["name"];
    $chip = $_POST["chip"];
    $day = $_POST["day"];
    $month = $_POST["month"];
    $year = $_POST["year"];
    if (!isset($_POST['Submit'])) { // if page is not submitted to itself echo the form
    ?>
    <html>
    <head>
      <title>..:: XXX ::..</title>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
      <link rel="stylesheet" type="text/css" href="style.css" />
    
    <script type="text/javascript">
    function validateFormOnSubmit(theForm) {
    var reason = "";
    
    
      reason += validateName(theForm.name);  
      reason += validateChip(theForm.chip);
      reason += validateDay(theForm.day);
      reason += validateMonth(theForm.month);
      reason += validateYear(theForm.year);
     
          
      if (reason != "") {
        alert("Error! The following error occurred during the processing:\n" + reason);
        return false;
      }
    
      alert("Thank you, all of your data were collected successfully!");
      return false;
    }
    function validateDay(fld) {
        var error = "";
     var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');  
    
       if (fld.value == "") {
            error = "You haven't enter a day.\n";
     } else if ((fld.value < 1) || (fld.value > 31)) {
            
            error = "The day cannot exceed values over 31 or be less than 01.\n";
           
        } else if (isNaN(fld.value)) {
            error = "The day field contains illegal characters.\n";
     
        } else if (!(stripped.length == 2)) {
            error = "The day is the wrong length.\n";
            
        }
        return error;
    }
    function validateMonth(fld) {
        var error = "";
     var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');  
    
       if (fld.value == "") {
            error = "You haven't enter a month.\n";
     } else if ((fld.value < 1) || (fld.value > 12)) {
            
            error = "The month cannot exceed values over 12 or be less than 01.\n";
           
        } else if (isNaN(fld.value)) {
            error = "The month field contains illegal characters.\n";
     
        } else if (!(stripped.length == 2)) {
            error = "The month is the wrong length.\n";
            
        }
        return error;
    }
    function validateYear(fld) {
        var error = "";
     var d = new Date();
     var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');  
    
       if (fld.value == "") {
            error = "You haven't enter a year.\n";
     } else if (fld.value < 1980) {
            error = "The year must be greater than 1980\n";
           
        } else if (isNaN(fld.value)) {
            error = "The year field contains illegal characters.\n";
     
        } else if (!(stripped.length == 4)) {
            error = "The year is the wrong length.\n";
      
       
        }
        return error;  
       
    }
    function validateName(fld) {
        var error = "";
        var illegalChars = /[^a-zA-Z]/;
     
     
        if (fld.value == "") {
            
            error = "You haven't enter dog's name.\n";
        } else if ((fld.value.length < 1) || (fld.value.length > 50)) {
            
            error = "Dog's name is the wrong length.\n";
        } else if (illegalChars.test(fld.value)) {
            
            error = "Dog's name contains illegal characters.\n";
           
        }
        return error;
    }
    
    function trim(s)
    {
      return s.replace(/^\s+|\s+$/, '');
    }
    
    function validateChip(fld) {
        var error = "";
        var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');  
    
       if (fld.value == "") {
            error = "You haven't enter a chip's number.\n";
           
        } else if (isNaN(fld.value)) {
            error = "Your chip number contains illegal characters.\n";
           
        } else if (!(stripped.length == 8)) {
            error = "Your chip number is the wrong length.\n";
           
        }
        return error;
    }
    </script>
    </head>
    <body>
    <TABLE cellpadding="0" cellspacing="0" border="1" bordercolor="black" align="center">
     <tr>
      <td valign="top" width="874" height="400>
       <table cellpadding="0" cellspacing="0" border="2">
    <strong>REGISTER YOUR DOG! Fill the blank below in order to register your dog in our database.</strong>
    <form method="post" onSubmit="return validateFormOnSubmit(this)" action="<?php echo $PHP_SELF;?>">
    <table summary="Verification Form">
    <table>
      <tbody>
      <tr>
        <td><label for="name"><strong>ENTER DOG'S NAME:</strong></label></td>
        <td><input name="name" size="41" maxlength="50" type="text"></td>
      </tr>   
      <tr>
        <td><label for="chip"><strong>ENTER CHIP'S NUMBER:</strong></label></td>
        <td><input name="chip" size="41" maxlength="25" type="text"></td>
      </tr>   
      
      <tr>
        <td><label for="month"><strong>DATE OF BIRTH</strong></label></td>
    	<td width="300">Day: <input name="day" size="2" maxlength="2" type="text"> Month: <input name="month" size="2" maxlength="2" type="text"> Year: <input name="year" size="4" maxlength="4" type="text"></td>
      </tr>
       
     
      <tr>
        <td> </td>
        <td><input name="Submit" value="Submit" type="submit" ></td>
        <td width="135"> </td>
      </tr>
     
      </tbody>
      </table>
      </form>
       </table>
       </td>
      </tr>
    </table>
    <?php
    } else {
    echo "The name of your dog is: ".$name.", and the chip's number is:";
    echo $chip."<br />";
    echo "It's birthday is on ".$day.",".$month.",".$year."!<br />";
    }
    ?> 
    </body>
    </html>
    <form method="post" onSubmit="return validateFormOnSubmit(this)" action="<?php echo $PHP_SELF;?>">
    onSubmit="return validateFormOnSubmit(this)" - , . , , ...
    Last edited by Black Hawk; 6th May 2010 at 20:31.
    ASRock P67 Extreme4 / i5-2500K / 32GB Geil Evo Leggera DDR3-1866 / MSI GTX 970 / Samsung 840 Evo 250GB / 1TB Samsung SpinPoint F3 / 60GB OCZ Vertex 2 / Corsair HX850i / Corsair 730GT Full Tower / Arctic Freezer 7 Pro Ver2 / LG 34UC79G-B 34"

  2. #2
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    javascript-a return false; .
    validateFormOnSubmit(), true, false; , .
    $PHP_SELF $_SERVER['PHP_SELF'];
    .

  3. #3
    Registered User Black Hawk's Avatar
    Join Date: Sep:2003
    Location:
    Posts: 871
    Quote Originally Posted by tedych View Post
    javascript-a return false; .
    validateFormOnSubmit(), true, false; , .
    $PHP_SELF $_SERVER['PHP_SELF'];
    .
    ! false true
    ,
    ASRock P67 Extreme4 / i5-2500K / 32GB Geil Evo Leggera DDR3-1866 / MSI GTX 970 / Samsung 840 Evo 250GB / 1TB Samsung SpinPoint F3 / 60GB OCZ Vertex 2 / Corsair HX850i / Corsair 730GT Full Tower / Arctic Freezer 7 Pro Ver2 / LG 34UC79G-B 34"

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |