表格发送后,Jquery if / else

时间:2017-10-29 08:59:09

标签: javascript jquery

我在一个集团中有一个连接形式,基本上visibility:hidden当表单被重新加载页面时。

但是这个集团又回到了隐藏之中。我想在页面重新加载后保留visibility:visible。但实际上,这段代码不起作用

(如果出现问题,变量$ styleblocconnexion由PHP处理设置)

 <script>

        $("#connexion-button").click(function(){

                $('#bloc-connexion').css("visibility", "visible");
                $('#fond-bloc-connexion').css("visibility", "visible");


            });  


        $("#submitconnect").click(function() {

            var styleblocconnexion = <?php if(isset($styleblocconnexion)) { echo $styleblocconnexion; } else { echo false; } ?>;
            if (styleblocconnexion != false)
            {
                $('#bloc-connexion').css("visibility", "visible");
                $('#fond-bloc-connexion').css("visibility", "visible");
            }

       });

   </script>

这是php traitment中设置$ styleblocconnexion

的代码
if(isset($_POST['submitconnect']))
{
$emailconnect = htmlspecialchars($_POST['emailconnect']);
$mdpconnect = sha1($_POST['mdpconnect']);
if(filter_var($emailconnect, FILTER_VALIDATE_EMAIL))
{
    $reqemailexist = $bdd->prepare("SELECT * FROM membres WHERE email = ?");
    $reqemailexist->execute(array($emailconnect));
    $resultemailexist = $reqemailexist->rowCount();
    if($resultemailexist == 1)
    {
        $resultemailexistfetch = $reqemailexist->fetch();
        if($mdpconnect == $resultemailexistfetch['mdp'])
        {
            $_SESSION['id'] = $resultemailexistfetch['id'];
            $_SESSION['email'] = $resultemailexistfetch['email'];
            header("Location: index.php?id=".$_SESSION['id']);
        }
        else
        {
            $msgerreurformconnect = "Mot de passe incorrect";
            $styleblocconnexion = "visible";
        }
    }
    else
    {
        $msgerreurformconnect = "Cette adresse email ne correspond à         aucun compte.";
        $styleblocconnexion = "visible";
    }
}
else
{
    $msgerreurformconnect = "Email invalide";
    $styleblocconnexion = "visible";
}
}

如您所见,$ styleblocconnexion仅在出现问题时设置。

1 个答案:

答案 0 :(得分:0)

我最终用document.ready:

做了
$(document).ready(function() {

        var styleblocconnexion = "<?php if(isset($styleblocconnexion)) {  echo $styleblocconnexion; } else { echo false; } ?>";
        if (styleblocconnexion != false)
        {
            $('#bloc-connexion').css("visibility", "visible");
            $('#fond-bloc-connexion').css("visibility", "visible");
        }

        });

谢谢