<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做到这一点?
答案 0 :(得分:0)
这假设您回发到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; ?>">