NOTICE

Adfly Links not working Find Direct Links HERE

How to build long forms using php in a short cut way

We can build a long form using php's foreach function in the following way. It makes the form more manageable and clean
<form name="myform" method="get" action="business.php" onsubmit="">
<?php

$postvalue=array("Name"=>"0","Email"=>"1","Phone"=>"2");
foreach($postvalue as $key => $value)
{
  echo ''.$key.'<input type="text" id="id'.$value.'" name="name['.$value.']" value=""><div id="err'.$value.'"></div><br>';
}

?>
<input type="submit" onclick="checkValidit()">
</form>
We can add any number of keys and values in array To get the values we can use following code
<?php
session_start();
$value = $_GET["name"];

foreach ($value as $uni) {
    $_SESSION[$uni] = $uni;
}

foreach ($value as $uni) {
    echo $_SESSION[$uni] . "<br>";
}
?>

0 comments :

Feel free to leave comment if you like above widget, have any questions or just say Hi! :)

jQuery Form Validation Email and Phone Number

HTML FORM
<form name="myform" method="get" action="business.php" onsubmit="">
Name<input type="text" id="id0" name="name[0]" value=""><div id="err0"></div><br>Email<input type="text" id="id1" name="name[1]" value=""><div id="err1"></div><br>Phone<input type="text" id="id2" name="name[2]" value=""><div id="err2"></div><br><input type="submit" onclick="checkValidit()">
</form>
jQuery Validation Code
<script type="text/javascript">
         function isValidEmailAddress(emailAddress) {
             var pattern = new RegExp(/^([w-.]+@([w-]+.)+[w-]{2,4})?$/);
             return pattern.test(emailAddress);
         };
         
         
         function isValidPhone(phone) {
             var pattern = new RegExp( /^d*[0-9](|.d*[0-9]|,d*[0-9])?$/);
             return pattern.test(phone);
         };
         
         function checkValidit()
         {
             if( !$("input").val() ) {
                 $("form").submit(function (e) {
                     e.preventDefault(); //prevent default form submit
                 });     
             }
         };
         
         
         
         
         $(function(){ 
             
             
             $('input').blur(function()
             {
                 if($(this).attr("id")=="id1")
                 {
                     // alert("email");
                     if( !isValidEmailAddress($(this).val()) ) 
                     {
                         $("#err1").html("Enter Valid Mail");
                     }else if(!$(this).val()){
                         $("#err1").html("Enter Mail");
                     }
                     else{
                         $("#err1").html("");
                     }
                     
                 }
                 else if($(this).attr("id")=="id2")
                 {
                     if( !isValidPhone($(this).val()) ) 
                     {
                         $("#err2").html("Enter Valid Phone");
                     }else if(!$(this).val()){
                         $("#err1").html("Enter Phone");
                     }
                     else{
                         $("#err2").html("");
                     }
                 }
                 else if($(this).attr("id")=="id0")
                 {
                     if( !$(this).val() ) 
                     {
                         $("#err0").html("Enter Name");
                     }
                     else{
                         $("#err0").html("");
                     }
                 }
             });
             
         });   
         
     </script>

0 comments :

Feel free to leave comment if you like above widget, have any questions or just say Hi! :)

Sector 17 Chandigarh @ Crazy Confessions India

0 comments :

Feel free to leave comment if you like above widget, have any questions or just say Hi! :)