Wednesday 12 September 2012

enquiry form validation using javascript


<html>
<head>
         <script language="JavaScript" type="text/JavaScript">
function Validate()
{
 var sName=document.frmContact.txtName.value;
 var stxtPhone=document.frmContact.txtPhone.value;

 var sEmail=document.frmContact.txtEmail.value;
 var sComments=document.frmContact.txtComments.value;

 if(sName == "")
  {
    alert("Please provide your name");
document.frmContact.txtName.focus();
return false;
  }
  if(stxtPhone!= ""){
  if(isNaN(stxtPhone)){

alert("Please Enter Valid Number");
document.frmContact.txtPhone.focus();
return false;
}
  }else{
      alert("Please Enter your Phone Number");
      document.frmContact.txtPhone.focus();
 return false;
  }

 if(sEmail == "")
  {
    alert("Please provide your email");
document.frmContact.txtEmail.focus();
return false;
  }
  var regex = /^[a-zA-Z0-9_.]+@([a-zA-Z0-9_.]+\.)+[a-zA-Z0-9.-]{2,3}$/;
  match = regex.test(sEmail)
  if(! match)
   {
     alert("Invalid email, please provide valid email");
     document.frmContact.txtEmail.focus();
     return false;  
   }
   
    if(sComments =="")
   {
    alert("Please provide your comments");
     document.frmContact.txtComments.focus();
     return false;    
   }
   if(document.frmContact.captcha_code.value != document.frmContact.txtSecCode.value){
alert("Security code doesnot match. Please enter valid security code.");
document.frmContact.txtSecCode.focus();
return false;
}
return true;
}
</script>

</head>
<body>
<form method="post" action="" name="frmContact" id="frmContact" onSubmit="return Validate()">

        <table width="90%"  border="0" cellpadding="0" cellspacing="1" class="text">
         <tr>
            <td colspan="3" height="5" align="left" valign="middle" class="white_text"></td>
            </tr>
 
            <tr>
            <td width="33%" height="25" align="left" valign="middle" class="green"><span class="mandatory">*&nbsp;</span>Name</td>

<td width="6%" align="left" valign="middle" class="white_text">:</td>
                <td width="61%" align="left" valign="middle"><input name="txtName" type="text" class="forTextfield" size="30" maxlength="50"/></td>
            </tr>
            <tr>
            <td height="25" align="left" valign="middle" class="green"><span class="mandatory">*&nbsp;</span>Phone</td>
<td width="6%" align="left" valign="middle" class="white_text">:</td>

           <td align="left" valign="middle"><input name="txtPhone" type="text" class="forTextfield" size="30" maxlength="15"/></td>
            </tr>

            <tr>
            <td height="25" align="left" valign="middle" class="green"><span class="mandatory">*&nbsp;</span>Email</td>

<td width="6%" align="left" valign="middle" class="white_text">:</td>
                <td align="left" valign="middle"><input name="txtEmail" type="text" class="forTextfield" size="30" maxlength="50"/></td>
            </tr>
            <tr>
           <td align="left" class="green" valign="middle"><span class="mandatory">&nbsp;</span> Address</td>
<td width="6%" class="white_text" align="left" valign="middle">:</td>

           <td align="left" valign="middle"><textarea name="txtAddress" rows="2" cols="25" class="forTextfield"></textarea></td>
            </tr>
<tr>
           <td align="left" class="green" valign="middle"><span class="mandatory">*&nbsp;</span>Enquiry</td>
<td width="6%" class="white_text" align="left" valign="middle">:</td>

           <td align="left" valign="middle"><textarea name="txtComments" rows="2" cols="25" class="forTextfield"></textarea></td>
            </tr>
           
           
            <tr>
              <td colspan="2" align="left" valign="middle">&nbsp;</td>
              <td height="60" align="left" valign="middle"><img src="captcha/CaptchaSecurityImages.php?width=100&height=40&characters=5" />
                <input type="hidden" name="captcha_code" value="<?=$_SESSION['code']?>"></td>
            </tr>
            <tr>
              <td align="left" valign="middle" class="green">Security Code</td>
              <td align="left" valign="middle" class="white_text">:</td>
              <td align="left" valign="middle"><input type="text" name="txtSecCode" class="forTextfield" id="txtSecCode"></td>
            </tr>
            <tr>
              <td colspan="2" align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
           <td colspan="2" align="left" valign="middle">&nbsp;</td>

           <td align="left" valign="middle"><input name="hid_submit" type="submit" class="forButton" id="hid_submit" value="submit"></td>
            </tr>
        </table>
        </form>



</body>
</html>

Thursday 6 September 2012

php basic programs

<?php    // functions with the arguments

function myfun($var1,$var2)
{   
 $output= $var1*$var2;
 //echo "$output".'<br/>';
}
$one=myfun('10','5');
$two=myfun('6','9');

echo "$one".'<br/>';
echo "$two";

// local and global varables with their scopes

$name='3kits';
function fun1()
{
    global $name;
    echo "welcome to $name with in the function ".'<br/><br/><br>';   
}

fun1();
echo "welcome to $name from outside funtion "."<br><br>";

// Arrays declaration and the execution
echo "arrays "."<br>";
$cart_array=array("tea","coffee","Milk");

echo "$cart_array[0] "."FIRST ITEM"."<br>";
echo "$cart_array[1] "."SECOND ITEM"."<br>";
echo "$cart_array[2] "."THIRD ITEM"."<br>"."<br>";

//echo Serializable($cart_array);    //not working (result is fatal error)


$cart_array1[]="raju"."<br>";
$cart_array1[]="suman"."<br>";
$cart_array1[]="tarun";
$cart_array1[]="uday";

echo $cart_array1[0];
echo $cart_array1[1]."<br>";


// associate arrays
echo "associate arrays "."<br>";

$cart_array_assoc["raju"]="25";
$cart_array_assoc["suman"]="30";
$cart_array_assoc["uday"]="35";
$cart_array_assoc["varun"]="40"."<br>";

echo "age of raju:".$cart_array_assoc["raju"]."<br>";
echo "age of suman".$cart_array_assoc["suman"];
echo "other way of the assoc array declaration"."<br>";
$cart_array_assoc_secondway=array("tomoto"=>"3.00",
                                    "potato"=>"5.00",
                                    "beans"=>"10.00","sapotas"=>"12.00","bananas"=>"2.00"   
                                    );


echo "Bananas rate in the market is:".$cart_array_assoc_secondway["bananas"]."<br>";
print_r($cart_array_assoc_secondway); //will print the values in a single lined fashion

//var_dump($cart_array_assoc_secondway)."from the var_dump ariable ";   //will print like the formatted way like their size and the values in the line by lin

// multi dimensional arrays
echo "multi dimensional arrays"."<br>";

$cart_array_multidimen=array("member1" =>array("name"=>"raju",           
                                                "height"=>"5.7",
                                               "weight"=>"55"
                                               ),
                             "member2"=>array("name"=>"raju1",           
                                                "height"=>"5.7",
                                               "weight"=>"55"
                                              ),
                            "member3"=>array("name"=>"raju2",           
                                                "height"=>"5.7",
                                               "weight"=>"55"
                                             )
                            );
                           
echo count($cart_array_multidimen)."<br>";
print_r($cart_array_multidimen);

?>
<?php
$shop = array( array( Title => "rose",
                      Price => 1.25,
                      Number => 15
                    ),
               array( Title => "daisy",
                      Price => 0.75,
                      Number => 25,
                    ),
               array( Title => "orchid",
                      Price => 1.15,
                      Number => 7
                    )
             );
echo '<u><h2 align="center">flowers shopping cart</h2></u>';
echo "<h1>Manual access to each element from associative array</h1>";

for ($row = 0; $row < 3; $row++)
{
    echo $shop[$row]["Title"]." costs ".$shop[$row]["Price"]." and you get minimum ".$shop[$row]["Number"];
    echo "<br />";
}
    echo "<h1>Using foreach loop to display elements</h1>";
    echo "<ol>";   // default it will print the heading values like 1.  2.
for ($row = 0; $row < 3; $row++)   //the variable must start from zero only
{
    echo "<li><b>The row number $row</b>";
    echo "<ul>";
    foreach($shop[$row] as $key => $value)
    {
        echo "<li>".$value."</li>";
    }
    echo "</ul>";
    echo "</li>";
}
echo "</ol>";
?>
<!--arrays in the arithmetic operations -->
<?php
$myArray = array(500.00, 300.00, 200.00, 400.00);
$result = 0;
foreach ($myArray as $key => $value) {
    $result = $result + $value;
}
$output = number_format($result);

?>

<h2>Rs:<?php echo $output; ?></h2>

<?php
$file_x="my_file.txt";
$createFile=touch($file_x);
if(file_exists($file_x))
{
   
echo "file has been created ";
   
}else
echo "file has not been created";


$target_file = "my_file.txt";
// Here we define the string data that is to be placed into the file
$target_file_data = "This is the string data or code I want to place in the newly created file.";
// Here we are creating a file(since it does not yet exist) and adding data to it
$handle = fopen($target_file, "w");
fwrite($handle, $target_file_data); // write it
fclose($handle);
// Here we are opening and appending to the file
$handle = fopen($target_file, "a");
// Here we define the string data that is to be appended to the data already in file
$target_file_data = "Here is more data I want to append to the file.";
fwrite($handle, $target_file_data); // write it
fclose($handle);

// Here we display the file contents by including it
include($target_file);

?>

<?php
//to write the string in the red colored text have to use it.

highlight_string(
  '<?php
     echo "this is the 3kits india ltd ";
 ?>'
 );

?>

<?php
// html encode and decode

$original_input = "<strong><em>Hello World!</em></strong>";
echo $original_input."origanl data" ;
echo "
<hr />
";
$html_encoded = htmlentities($original_input);
echo $html_encoded."after encoding";
echo "
<hr />
";
$html_decoded = html_entity_decode($html_encoded);
echo $html_decoded."after decoding";
?>