Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 在joomla中使用javascript进行表单验证_Validation_Forms_Joomla - Fatal编程技术网

Validation 在joomla中使用javascript进行表单验证

Validation 在joomla中使用javascript进行表单验证,validation,forms,joomla,Validation,Forms,Joomla,我想使用表单验证。我已经使用了JavaScript,并且我已经下载了COMPHPH0.1ALPHA-J15TAR组件来编写PHP代码,但是空白条目会转到数据库。 请引导我。。。 示例代码在这里 <script language="javascript" type="text/javascript"> function Validation() { if(document.getElementById("name").value=="") { document.get

我想使用表单验证。我已经使用了JavaScript,并且我已经下载了COMPHPH0.1ALPHA-J15TAR组件来编写PHP代码,但是空白条目会转到数据库。 请引导我。。。 示例代码在这里

<script language="javascript" type="text/javascript">
 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;
 }


</script>


<?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(); 
   }

 }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
 .td{
  background-color:#FFFFFF;
  color:#000066;
  width:100px;
 }
 .text{
  border:1px solid #0033FF;
  color:#000000;
 }
</style>

</head>
<body>
<form id="form1" method="post">
<input type="hidden" name="check" value="post"/>

 <table border="0" align="center" cellpadding="2" cellspacing="2">
  <tr>
   <td colspan="3" style="text-align:center;"><span style="font-size:24px;color:#000066;">Feedback Form</span></td>
  </tr>
  <tr>
   <td class="td">Name</td>
   <td><input type="text" id="name" name="name" class="text" ></td>
   <td style="font-style:italic;color:#FF0000;" id="nameerr"></td>
  </tr>
  <tr>
   <td class="td">E-mail</td>
   <td><input type="text" id="Email" name="Email"  class="text"></td>
   <td style="font-style:italic;color:#FF0000;" id="emailerr"></td>
  </tr>
  <tr>
   <td class="td">Contact No</td>
   <td><input type="text" id="Phone" name="Phone"  maxlength="15" class="text"></td>
   <td style="font-style:italic;color:#FF0000;" id="Phoneerr"></td>
  </tr>
  <tr>
   <td class="td">Your Society</td>
   <td><input type="text" id="society" name="society"  class="text"></td>
   <td style="font-style:italic;color:#FF0000;" id="societyerr"></td>
  </tr>
  <tr>
   <td class="td">Occupation</td>
   <td><input type="text" id="occupation" name="occupation"  class="text"></td>
   <td style="font-style:italic;color:#FF0000;" id="occupationerr"></td>
  </tr>
  <tr>
   <td class="td">Feedback</td>
   <td><textarea name="feedback" id="feedback" class="text"></textarea></td>
   <td style="font-style:italic;color:#FF0000;" id="feedbackerr"></td>
  </tr>
  <tr>
   <td colspan="3" style="text-align:center;">
    <input type="submit" value="Submit" id="submit" onClick="Validation();" />
    <input type="reset" value="Reset" onClick="Resetme();" />
   </td>
  </tr> 
  </table>
</form>
</body>
</html>

函数验证()
{
if(document.getElementById(“name”).value==“”)
{
document.getElementById(“nameerr”).innerHTML=“输入名称”;
document.getElementById(“名称”).style.backgroundColor=“黄色”;
}
其他的
{
document.getElementById(“nameerr”).innerHTML=“”;
document.getElementById(“名称”).style.backgroundColor=“白色”;
}
if(document.getElementById(“email”).value==“”)
{
document.getElementById(“emailerr”).innerHTML=“输入电子邮件”;
document.getElementById(“email”).style.backgroundColor=“黄色”;
}
其他的
{
document.getElementById(“emailerr”).innerHTML=“”;
document.getElementById(“email”).style.backgroundColor=“白色”;
}
if(document.getElementById(“电话”).value==“”)
{
document.getElementById(“phoneerr”).innerHTML=“输入联系人编号”;
document.getElementById(“电话”).style.backgroundColor=“黄色”;
}
其他的
{
document.getElementById(“phoneerr”).innerHTML=“”;
document.getElementById(“电话”).style.backgroundColor=“白色”;
}
if(document.getElementById(“society”).value==“”)
{
document.getElementById(“societyerr”).innerHTML=“进入社会”;
document.getElementById(“society”).style.backgroundColor=“黄色”;
}
其他的
{
document.getElementById(“societyerr”).innerHTML=“”;
document.getElementById(“society”).style.backgroundColor=“白色”;
}
if(document.getElementById(“占领”).value==“”)
{
document.getElementById(“occupationerr”).innerHTML=“输入职业”;
document.getElementById(“职业”).style.backgroundColor=“黄色”;
}
其他的
{
document.getElementById(“职业错误”).innerHTML=“”;
document.getElementById(“职业”).style.backgroundColor=“白色”;
}
if(document.getElementById(“反馈”).value==“”)
{
document.getElementById(“feedbackerr”).innerHTML=“输入反馈”;
document.getElementById(“反馈”).style.backgroundColor=“黄色”;
}
其他的
{
document.getElementById(“feedbackerr”).innerHTML=“”;
document.getElementById(“反馈”).style.backgroundColor=“白色”;
}
if(document.getElementById(“名称”).value==“document.getElementById(“电子邮件”).value==”
||document.getElementById(“电话”).value==“document.getElementById(“社会”).value==”“
||document.getElementById(“职业”).value==“”| | document.getElementById(“反馈”).value==“”)
返回false;
其他的
返回true;
}

更改代码的这一行:

<input type="submit" value="Submit" id="submit" onClick="Validation();" />

关于这一点:

<input type="submit" value="Submit" id="submit" onClick="return Validation();" />

或者,您可以将此函数名放在表单标记中,例如:

<form id="form1" method="post" onSubmit="return Validation();">

并将提交按钮代码保留如下:

<input type="submit" value="Submit" id="submit" />


如果您正确地完成了所有其他操作,这将解决验证问题。

更改代码的这一行:

<input type="submit" value="Submit" id="submit" onClick="Validation();" />

关于这一点:

<input type="submit" value="Submit" id="submit" onClick="return Validation();" />

或者,您可以将此函数名放在表单标记中,例如:

<form id="form1" method="post" onSubmit="return Validation();">

并将提交按钮代码保留如下:

<input type="submit" value="Submit" id="submit" />


如果您已经正确地完成了所有其他工作,那么这应该可以解决您的验证问题。

这里有一个关于这个问题的joomla文档链接。它有一个内置的formvalidation机制。 这是给joomla 1.5的


对于joomla 1.6,这里有一个关于这个问题的joomla文档链接。它有一个内置的formvalidation机制。 这是给joomla 1.5的

对于joomla 1.6