如何在PHP代码中使用JavaScript布尔输出?
如何在中调用函数如何在PHP代码中使用JavaScript布尔输出?,php,javascript,function,return-value,Php,Javascript,Function,Return Value,如何在中调用函数registerUser() if (formvalidate()==true); // i am trying here registerUser(); // shall be called if formvalidate() is true 以下是我使用的代码: <?PHP include("functions.php"); if(isset($_POST['Submit1'])) { ?> <script type="text/javascrip
registerUser()
if (formvalidate()==true); // i am trying here
registerUser(); // shall be called if formvalidate() is true
以下是我使用的代码:
<?PHP
include("functions.php");
if(isset($_POST['Submit1']))
{
?>
<script type="text/javascript">
if(formvalidate()==true);//i am trying here
registerUser();this will do if formvalidat return true
helloworld();
<?php }; ?>
<script type="text/javascript">
function formvalidate()
{
if( document.Form.first_name.value == "" )
{
alert( "Please insert your name." );
document.Form.first_name.focus() ;
return false;
}
if( document.Form.last_name.value == "" )
{
alert( "Please insert your last name." );
document.Form.last_name.focus() ;
return false;
}
if( document.Form.password.value == "" )
{
alert( "Please insert your password." );
document.Form.password.focus() ;
return false;
}
if( document.Form.username.value == "" )
{
alert( "Please insert your user name(display name) ." );
document.Form.username.focus() ;
return false;
}
if ( ( Form.gender[0].checked == false ) && ( Form.gender[1].checked == false ) )
{
alert( "Please select your gender." );
document.Form.gender.focus() ;
return false;
}
if( document.Form.birthdate_year.value == "" )
{
alert( "Please insert your birthyear." );
document.Form.birthdate_year.focus() ;
return false;
}
if( document.Form.birthdate_day.value == "" )
{
alert( "Please insert your birthDAY." );
document.Form.birthdate_day.focus() ;
return false;
}
if( document.Form.birthdate_month.value == "" )
{
alert( "Please insert your birthmonth." );
document.Form.birthdate_month.focus() ;
return false;
}
//gender $_POST['birthdate_year']."-".$_POST['birthdate_month']."-".$_POST['birthdate_day']
if( !validateEmail())
{
alert( "Please insert your Email address." );
document.Form.email.focus() ;
return false;
}
if( document.Form.zip.value == "" ||isNaN( document.Form.Pin.value ) )
{
alert( "Please insert the pin code." );
document.Form.zip.focus() ;
return false;
}
if( document.Form.countries.value == "" )
{
alert( "Please select your country!" );
return false;
}
return( true );
}
function validateEmail()
{
var emailID = document.Form.email.value;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || ( dotpos - atpos < 2 ))
{
return false;
}
return( true );
}
</script>
如果(formvalidate()==true)//我在这里尝试
registerUser();如果formvalidat返回true,则可以执行此操作
helloworld();
函数formvalidate()
{
if(document.Form.first_name.value==“”)
{
提醒(“请插入您的姓名”);
document.Form.first_name.focus();
返回false;
}
如果(document.Form.last_name.value==“”)
{
提醒(“请插入您的姓氏”);
document.Form.last_name.focus();
返回false;
}
如果(document.Form.password.value==“”)
{
警告(“请插入您的密码”);
document.Form.password.focus();
返回false;
}
如果(document.Form.username.value==“”)
{
警告(“请插入您的用户名(显示名称)。”;
document.Form.username.focus();
返回false;
}
if((Form.gender[0].checked==false)和&(Form.gender[1].checked==false))
{
提醒(“请选择您的性别”);
document.Form.gender.focus();
返回false;
}
如果(document.Form.birthdate\u year.value==“”)
{
提醒(“请插入您的生日。”);
document.Form.birthdate_year.focus();
返回false;
}
如果(document.Form.birthdate\u day.value==“”)
{
提醒(“请插入您的生日”);
document.Form.birthdate_day.focus();
返回false;
}
如果(document.Form.birthdate\u month.value==“”)
{
提醒(“请插入您的生日。”);
document.Form.birthdate_month.focus();
返回false;
}
//性别$\u POST['birthdate\u year']。“-”$\u POST['birthdate\u month']。“-”$\u POST['birthdate\u day']
如果(!validateEmail())
{
提醒(“请插入您的电子邮件地址”);
document.Form.email.focus();
返回false;
}
if(document.Form.zip.value==“”| | isNaN(document.Form.Pin.value))
{
警告(“请插入pin码”);
document.Form.zip.focus();
返回false;
}
如果(document.Form.countries.value==“”)
{
警告(“请选择您的国家!”);
返回false;
}
返回(真);
}
函数validateEmail()
{
var emailID=document.Form.email.value;
atpos=emailID.indexOf(“@”);
dotpos=emailID.lastIndexOf(“.”);
if(atpos<1 | |(dotpos-atpos<2))
{
返回false;
}
返回(真);
}
使用以下方法:
<form name ="MyForm" method ="post" action ="#" onSubmit="return(formvalidate());">
</form>
Rahter在提交页面后检查,您可以在表单标签中添加onsubmit=“return formvalidate();”