php - 在 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>
解决方案
你只需要在 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>
推荐阅读
- handlebars.js - 如何在车把的 if 条件内使用 if
- laravel - Laravel Seeder - 使用我自己通过播种机选择的电子邮件创建 2 个用户
- node.js - 棱镜错误:无法连接到 http://localhost:4466 的服务器
- python - 如何检测值高于某个阈值的连续子列表?
- angular - ng如果所选项目是特定值,则
- android - 存储更新时组件无法正确重新渲染
- azure - AzCopy - 什么是返回值?
- python - 如何将这些网站归类为不工作?
- oracle - 在oracle,mule 4中插入clob数据类型?
- java - 一个 Serverless 调度的 java 函数应该实现什么接口?