首页 > 解决方案 > 在 php 代码中替换 html 元素的内容

问题描述

我正在编写一个 php 文件,我想在设置 get 变量时在现有 html 元素中显示不同的内容。

现在我想要设置单词“密码重置成功”而不是“输入您的电子邮件以重置密码”或通过在设置 GET 变量时<p>隐藏当前标签来添加包含所需单词的新标签。<p>但我不知道如何做到这一点。我检查了不同的时间,但我失败了。如果有人可以帮助我做到这一点,我真的很感激。

这是我的代码。

 <div class="login-box-body">
<!--Want to replace this text as Password Reset Was Success or add a new <p> tag containing  the required words by hiding current <p> tag -->
            <p class="login-box-msg">Enter your Email to reset the password</p> 
        
        
         <?php require '_inc/msg.php' ?>

         <!--  Check if GET variable is set or not -->
        <?php if (isset($_GET['code'])) {

           echo '<style>.formPsw{ display:none;}</style>';
  
        } ?>

        <form action="" method="post" class="formPsw">
            <div class="form-group has-feedback emailBox" >
                <input type="email" name="email" class="form-control" placeholder="Email" data-validation="email required">
                <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="row">
                <div class="col-xs-8">
                </div>
                <!-- /.col -->
                <div class="col-xs-4 sendEmailBtn">
                    <input type="submit" name="send" class="btn btn-primary btn-block btn-flat" value="send"/>
                </div>
                <!-- /.col -->
            </div>
        </form>
        <?php if (!empty($_POST['send'])) {
            echo 'Please check your email ('.$_POST['email'].'). We send password reset link to your email.';
        } ?>
    </div>

标签: phphtml

解决方案


你只需要在 if 条件下包装:

<div class="login-box-body">
    <?php if(isset($_GET['the_get_var_you_are_expecting'])){ ?>
        <p class="success">Password Reset Was Success</p>

    <?php } else { ?>
        <!--Want to replace this text as Password Reset Was Success or add a new <p> tag containing  the required words by hiding current <p> tag -->
        <p class="login-box-msg">Enter your Email to reset the password</p>

        <?php require '_inc/msg.php' ?>

        <!--  Check if GET variable is set or not -->
        <?php if (isset($_GET['code'])) {

            echo '<style>.formPsw{ display:none;}</style>';

        } ?>

        <form action="" method="post" class="formPsw">
            <div class="form-group has-feedback emailBox" >
                <input type="email" name="email" class="form-control" placeholder="Email" data-validation="email required">
                <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="row">
                <div class="col-xs-8">
                </div>
                <!-- /.col -->
                <div class="col-xs-4 sendEmailBtn">
                    <input type="submit" name="send" class="btn btn-primary btn-block btn-flat" value="send"/>
                </div>
                <!-- /.col -->
            </div>
        </form>
        <?php if (!empty($_POST['send'])) {
            echo 'Please check your email ('.$_POST['email'].'). We send password reset link to your email.';
        } ?>

    <?php } ?>
</div>

推荐阅读