表单验证灯箱php if / else语句

时间:2011-08-31 20:12:44

标签: php javascript forms lightbox submission

嘿伙计们,我正在努力解决这个问题。

我想我了解灯箱及其工作原理。我在游戏服务器上使用它并且工作正常;直到我在php中的if else语句中使用它来测试表单验证。如果用户填写表单不正确,则应弹出失败图像的灯箱,但事实并非如此。我希望这个美好视线中的某个人可以帮助我

<html> 
<?php
<head>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/j``avascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
 <link rel="stylesheet" type="text/css" href="css.css" />  
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
</head> 
$EmailAddres = $_POST[Email];
$FirstName = $_POST[FName];
$LastName = $_POST[LName];
$PhoneNumber = $_POST[Phone];
$AltPhoneNumber = $_POST[AltPhone];


//This is the testing and the validation testing
$flag="OK";
$msg="";
$todo="test";



if(!ereg("^[-A-Za-z]*$",$FirstName)){
     echo "Invalid first Name";
     $flag="NOTOK";
}

if(!ereg("^[-A-Za-z]*$",$LastName)){
   echo "Invalid Last Name";
   $flag="NOTOK";
}


if(!ereg("^[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[@]{1}[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[.]{1}[A-Za-    z]{2,5}$",$_POST[Email])){
     echo "Invalid Email Address";
     $flag="NOTOK";
}

/*This is to validate the phone number input */ 
    if(!ereg("[0-9]{10,11}", $PhoneNumber)){
         echo "Invalid phone number"; 
         $flag="NOTOK";
} 


if($flag == "NOTOK"){
    echo '<p><a href="images/fail.png" rel="lightbox" class="lightbox_trigger"></a></p>';
   // echo "something is definitely wrong here";  
}
?>
</html> 

1 个答案:

答案 0 :(得分:0)

用PHP打印出链接引用是不够的。你需要在运动中设置javascript。

以下是解决您完全相同问题的人的简短博客文章。它比较旧了,但确实有效。

http://www.bram.us/2007/07/30/my-code-snippet-automatically-start-lightbox-on-page-load/