【问题标题】:Replace the content of an an html element within a php code在 php 代码中替换 html 元素的内容
【发布时间】:2020-10-22 23:04:12
【问题描述】:

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

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

这是我的代码。

 <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>

【问题讨论】:

标签: php html


【解决方案1】:

你只需要在 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>

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 1970-01-01
    • 2018-02-18
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 2020-04-27
    • 2021-10-08
    • 2017-12-22
    相关资源
    最近更新 更多