如何在用PHP提交表单后更改css类?

如何在用PHP提交表单后更改css类?,php,html,Php,Html,这是假设您正在发回相同的页面,您的action='暗示了这一点 您可以执行以下操作: <form action="" method="post"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"><i class="fa fa-use

这是假设您正在发回相同的页面,您的
action='
暗示了这一点

您可以执行以下操作:

   <form action="" method="post">
            <div class="form-group">
                <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-user fa-fw"></i></span>
                <input class="form-control" type="text" placeholder="Enter your username here..." name="username">
                </div>
            </div>
            <div class="form-group <?php //apply php code later ?>"> 
                <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-envelope fa-fw"></i></span>
                <input class="form-control" type="text" placeholder="Enter your email here..." name="email">
                </div>
            </div>
            <div class="form-group <?php //apply php code later ?>">
                <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
                <input class="form-control" type="text" placeholder="Enter your password here..." name="password">
                </div>
            </div>
            <div class="form-group <?php //apply php code later ?>"> 
                <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
                <input class="form-control" type="text" placeholder="Retype your password here..." name="password_retype">
                </div>
            </div>
            <hr class="linestyle">
            <p>Which comparison operator is used to compare variables/values in PHP?</p>
            <div class="form-group">
                <input class="form-control" type="text" placeholder="Answer the question here..." name="question">
            </div>
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="checkbox">I agree to the <a href="#">rules</a> of this forum.
                </label>
            </div>
            <p class="rules" style="font-size:10px;">Breaking the rules by any means will result in a permanent ban.</p>
            <input class="btn btn-success fullwidth" type="submit" value="Register">
        </form>

PHP代码仅在第一次生成页面时运行;您不能让PHP在用户对页面执行某些操作后执行。(这就是你想要做的吗?你的问题有点不清楚)那么用什么来代替php来做这件事呢?是的,我正试图做你描述的事情。老实说,我不确定你到底想做什么。如果要在不重新加载页面的情况下检查用户名是否已存在,则必须使用JavaScript对服务器进行AJAX调用。@oxguy3如果他发回同一个php文件,他可以这样做,而他的
action='
会导致此问题。
<div class="form-group <?php if(isset($_POST)) { echo 'posted-class'; } ?>"> 
<?php
$classAfterPosted = ''; //default blank
if(isset($_POST))
{
  $classAfterPosted = 'posted-class'; 
} 
?>
...
 <div class="form-group <?php echo $classAfterPosted; ?>">