title: Form Validation using javascript in joomla
body: <p>I want to use form validation. I have used javascript for this and I have downloaded the com_php0.1alpha-J15.tar component for writing php code but the blank entries are goes to the database.
  Please guide me...
  sample code is here...</p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
   function Validation()
   {
    if(document.getElementById("name").value=="")
    {
     document.getElementById("nameerr").innerHTML="Enter Name";
     document.getElementById("name").style.backgroundColor = "yellow";
    }
    else
    {
     document.getElementById("nameerr").innerHTML="";
     document.getElementById("name").style.backgroundColor = "White";
    }
    if(document.getElementById("email").value=="")
    {
     document.getElementById("emailerr").innerHTML="Enter Email";
     document.getElementById("email").style.backgroundColor = "yellow";
    }
    else
    {
     document.getElementById("emailerr").innerHTML="";
     document.getElementById("email").style.backgroundColor = "White";
            }
    if(document.getElementById("phone").value=="")
    {
     document.getElementById("phoneerr").innerHTML="Enter Contact No";
     document.getElementById("phone").style.backgroundColor = "yellow";
    }
    else
    {
     document.getElementById("phoneerr").innerHTML="";
     document.getElementById("phone").style.backgroundColor = "White";
                  }
    if(document.getElementById("society").value=="")
    {
     document.getElementById("societyerr").innerHTML="Enter Society";
     document.getElementById("society").style.backgroundColor = "yellow";
    }
    else
    {
     document.getElementById("societyerr").innerHTML="";
     document.getElementById("society").style.backgroundColor = "White";
    }
    if(document.getElementById("occupation").value=="")
    {
     document.getElementById("occupationerr").innerHTML="Enter Occupation";
     document.getElementById("occupation").style.backgroundColor = "yellow";
           }
    else
    {
     document.getElementById("occupationerr").innerHTML="";
     document.getElementById("occupation").style.backgroundColor = "White";
           }
    if(document.getElementById("feedback").value=="")
    {
     document.getElementById("feedbackerr").innerHTML="Enter Feedback";
     document.getElementById("feedback").style.backgroundColor = "yellow";
    }
    else
    {
     document.getElementById("feedbackerr").innerHTML="";
     document.getElementById("feedback").style.backgroundColor = "White";
    }
    if(document.getElementById("name").value=="" || document.getElementById("email").value=="" 
    || document.getElementById("phone").value=="" || document.getElementById("society").value=="" 
    || document.getElementById("occupation").value=="" || document.getElementById("feedback").value=="")
     return false;
    else
     return true;
   }
  
  
  &lt;/script&gt;
  
  
  &lt;?php
   if(isset($_POST['submit']))
   {
     $conn = mysql_connect('localhost','root','');
     mysql_select_db('society_f',$conn);
  
     $name = $_POST['name'];
     $email =  $_POST['email'];
     $phone =  $_POST['phone'];
     $society =  $_POST['society'];
     $occupation = $_POST['occupation'];
     $feedback =  $_POST['feedback'];
  
     $qry =  "insert into feedback values(null". ",'" . $name . "','" . $email . "','" . $phone . "','" . $society . "','" . $occupation . "','" . $feedback . "')" ;
     $res = mysql_query($qry);
     if(!$res)
     {
      echo "Could not run a query" . mysql_error(); 
      exit(); 
     }
  
   }
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;style type="text/css"&gt;
   .td{
    background-color:#FFFFFF;
    color:#000066;
    width:100px;
   }
   .text{
    border:1px solid #0033FF;
    color:#000000;
   }
  &lt;/style&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form id="form1" method="post"&gt;
  &lt;input type="hidden" name="check" value="post"/&gt;
  
   &lt;table border="0" align="center" cellpadding="2" cellspacing="2"&gt;
    &lt;tr&gt;
     &lt;td colspan="3" style="text-align:center;"&gt;&lt;span style="font-size:24px;color:#000066;"&gt;Feedback Form&lt;/span&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td class="td"&gt;Name&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" id="name" name="name" class="text" &gt;&lt;/td&gt;
     &lt;td style="font-style:italic;color:#FF0000;" id="nameerr"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td class="td"&gt;E-mail&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" id="Email" name="Email"  class="text"&gt;&lt;/td&gt;
     &lt;td style="font-style:italic;color:#FF0000;" id="emailerr"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td class="td"&gt;Contact No&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" id="Phone" name="Phone"  maxlength="15" class="text"&gt;&lt;/td&gt;
     &lt;td style="font-style:italic;color:#FF0000;" id="Phoneerr"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td class="td"&gt;Your Society&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" id="society" name="society"  class="text"&gt;&lt;/td&gt;
     &lt;td style="font-style:italic;color:#FF0000;" id="societyerr"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td class="td"&gt;Occupation&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" id="occupation" name="occupation"  class="text"&gt;&lt;/td&gt;
     &lt;td style="font-style:italic;color:#FF0000;" id="occupationerr"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td class="td"&gt;Feedback&lt;/td&gt;
     &lt;td&gt;&lt;textarea name="feedback" id="feedback" class="text"&gt;&lt;/textarea&gt;&lt;/td&gt;
     &lt;td style="font-style:italic;color:#FF0000;" id="feedbackerr"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td colspan="3" style="text-align:center;"&gt;
      &lt;input type="submit" value="Submit" id="submit" onClick="Validation();" /&gt;
      &lt;input type="reset" value="Reset" onClick="Resetme();" /&gt;
     &lt;/td&gt;
    &lt;/tr&gt; 
    &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>