duanbei3747 2014-05-09 14:37
浏览 13

还有其他方法可以在其他页面进行验证吗?

hi i tried to make validation using php but i want to do it in another page like (make form action="page.php") and do validation and send data in page.php but form in page login.html i don't like to do all php code in the same page by using PHP_SELF

thanks and sorry for my bad english

html code (login.html)

<form class="well" role="form" action="page.php" method="post">
                <input type="text" name="user" class="form-control" placeholder="User Name"/><br><br>
                <span><?php echo $userErr ?></span>
                <input type="password" name="pass" class="form-control"placeholder="Password" /><br><br>
                <span><?php echo $passErr ?></span>

                <input type="submit" value="Login" class="btn btn-success" style="margin-left: 45px;"/>
                <a data-toggle="modal" href="#myModal" class="btn btn-info">forget your password?</a>

            </form>

php code (page.php)

$userErr = $passErr = "";
$user = $pass = "";
if($_SERVER['REQUEST_METHOD']=="POST"){
   if(empty($_POST['user'])){
$userErr = "Please Insert Your Name";   
}elseif(strlen($_POST['user'])>20){
$userErr = "Your Name Is greater than 20 char";
$user = $_POST['user'];
}
else{
    $user = $_POST['user'];
}
if(empty($_POST['pass'])){
    $passErr ="Pleaes your password";
}
else{
    $pass = $_POST['pass'];
}
 }
  • 写回答

2条回答 默认 最新

  • douwayuan3063 2014-05-09 14:47
    关注

    I tried to decipher your question. Apparently you want to have a form on a page called 'login.html', then have it be validated by a script called 'page.php' and then return to 'login.html', possibly only if validation failed. This could be accomplished with the header() function. For example, if you want to return to the login.html-page if validation fails:

    page.php

    //Validation code here
    
    if ($validated == true)
     {
     //Validation succes
     }
    else
     {
     header('Location: login.html');
     }
    

    Notice that the header()-function won't work if you already printed something to the page.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集