我有这个代码,在提交时,它会从数组生成随机数。
<?php
if(isset($_POST['roll'])) {
$randarray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$randselect = array_rand($randarray);
$nr = $randarray[$randselect];
echo '<p class="btn btn-info"> Branch: '. $nr. '</p>';
}
?>
<form action="#" method="post">
<button type="submit" class="btn btn-default" name="roll">Roll Branch </button>
</form>
我想要做的是在提交表单后,该按钮将被禁用。有什么想法吗?
答案 0 :(得分:2)
如果按下按钮,只需添加disabled
,例如
<button type="submit" class="btn btn-default" name="roll" <?php echo isset($_POST["roll"]) ? "disabled" : "";?>>Roll Branch </button>
答案 1 :(得分:2)
你可以这样做:
<button type="submit" class="btn btn-default" name="roll" <?php echo isset($_POST['roll']) ? 'disabled="true"' : ''; ?> >Roll Branch </button>
答案 2 :(得分:1)
为按钮标记添加onclick="this.disabled='true';"
答案 3 :(得分:0)
页面发布后未启用它,出现了一些错误。 在我的情况下,我的注册页面有一个提交按钮。下面是代码:
<form action="" method="post" id="signup-form" name="signup-form">
<div class="row">
<div class="form-group col-md-12 mb-4">
<input type="text" class="form-control input-lg" id="txtFormNo" name="txtFormNo" aria-describedby="nameHelp" placeholder="Form No" required readonly>
</div>
<div class="form-group col-md-12 mb-4">
<label for="standard">Select Standard</label>
<select class="form-control" id="standard" name="standard" required>
<option>FYJC</option>
<option>SYJC</option>
</select>
</div>
<div class="col-sm-12">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="txtSeatNo">SSC Seat No</label>
<input type="text" class="form-control input-lg" id="txtSeatNo" name="txtSeatNo" autocomplete="off" aria-describedby="nameHelp" placeholder="SSC Seat No" maxlength="7" required>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="confirmSeatNo">Re-enter SSC Seat No</label>
<input type="text" class="form-control input-lg" id="confirmSeatNo" name="confirmSeatNo" autocomplete="off" aria-describedby="nameHelp" placeholder="Re-enter SSC Seat No" maxlength="7" required>
</div>
</div>
</div>
</div>
<?php if (isset($_GET['flag']) != 'newsyjc') { ?>
<div class="col-sm-12">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="txtSscAppNo">Enter Unique Application ID</label>
<input type="text" class="form-control input-lg" placeholder="UNIQUE APPLICATION ID" autocomplete="off" name="txtSscAppNo" id="txtSscAppNo" maxlength="6" required />
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="confirmSscAppNo">Re-enter Unique Application ID</label>
<input type="text" class="form-control input-lg" placeholder="Re-enter UNIQUE APPLICATION ID" autocomplete="off" name="confirmSscAppNo" id="confirmSscAppNo" maxlength="6" required />
</div>
</div>
</div>
</div>
<?php } ?>
<div class="col-sm-12">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="txtContact">Enter Contact No.</label>
<input type="text" class="form-control input-lg" id="txtContact" name="txtContact" autocomplete="off" placeholder="Contact" maxlength="10" required>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="confirmContact">Re-enter Contact No.</label>
<input type="text" class="form-control input-lg" id="confirmContact" name="confirmContact" autocomplete="off" placeholder="Re-enter Contact" maxlength="10" required>
</div>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="txtEmail">Enter Email ID</label>
<input type="email" class="form-control input-lg" id="txtEmail" name="txtEmail" aria-describedby="emailHelp" autocomplete="off" placeholder="Email ID" required>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="confirmEmail">Re-enter Email ID</label>
<input type="email" class="form-control input-lg" id="confirmEmail" name="confirmEmail" aria-describedby="emailHelp" autocomplete="off" placeholder="Re-enter Email ID" required>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="d-inline-block mr-3">
<label class="control control-checkbox">
<input type="checkbox" required />
<div class="control-indicator"></div>
I Agree the terms and conditions
</label>
</div>
<button type="submit" class="btn btn-lg btn-primary btn-block mb-4" name = "btnSignup" id = "btnSignup"
<?php echo isset($_POST["btnSignup"]) ? "disabled" : "";?> >Sign Up</button>
<p>Already have an account?
<a class="text-blue" href="login.php">Sign in</a>
</p>
</div>
</div>
</form>
PHP代码:
if (isset($_POST['btnSignup'])) {
$standard = trim($_POST['standard']);
$SeatNo = trim($_POST['txtSeatNo']);
$cSeatNo = trim($_POST['confirmSeatNo']);
$FormNo = trim($_POST['txtFormNo']);
$contact = trim($_POST['txtContact']);
$cContact = trim($_POST['confirmContact']);
$Email = trim($_POST['txtEmail']);
$cEmail = trim($_POST['confirmEmail']);
$code = md5(uniqid(rand()));
$stmt = $user->runQuery("SELECT * FROM stud_personal_details WHERE SeatNo=:SeatNo");
$stmt->execute(array(":SeatNo"=>$SeatNo));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($flag == 'newsyjc') {
$SscAppNo = '';
$cSscAppNo = '';
if ($stmt->rowCount() > 0) {
$msg = "<div class='alert alert-error'>
<strong>Sorry !</strong> Seat No is Already Registered.<br>
Please enter your correct Seat No OR <a class='btn btn-success btn-lg' href='login.php'>Click here to login !</a>
</div>";
} else if ($standard == 'SYJC') {
if ($user->stud_personal_details($SeatNo, $FormNo, $SscAppNo, $Password, $contact, $code, $Email) &&
$user->stud_admission_details($SeatNo, $SscAppNo) &&
$user->stu_app($SeatNo, $code) &&
$user->Marks($SeatNo) ) {
$user->send_sms($SeatNo, $Password, $Email);
$msg = "<div class='alert alert-success' role='alert'>
<strong>Success!</strong> Your account is created.<br>
Password have been SMS on ".$contact." and mailed at ".$Email."<br>
<p><a class='text-blue' href='login.php'>Click here to login !</a></p>
</div>";
//header("refresh:3;login.php?flag=".$flag);
} else {
$msg = "<div class='alert alert-danger' role='alert'>
<strong>Sorry !</strong> Something went wrong.<br>
Contact college office or IT Charge of College.
</div>";
}
}
} else if ($days > 0) {
$SscAppNo = trim($_POST['txtSscAppNo']);
$cSscAppNo = trim($_POST['confirmSscAppNo']);
if (strlen($SeatNo) != 7 ) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> SSC Seat Number is a 7 alpha-numberic combination.<br>
Please enter again.
</div>";
} else if ($cSeatNo !== $SeatNo) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry!</strong> SSC Seat Number doesn't match.<br>
Please enter again.
</div>";
} else if (strlen($SscAppNo) != 6 ) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> UNIQUE APPLICATION ID should be 6 numberic value.<br>
Please enter again.
</div>";
} else if ($cSscAppNo !== $SscAppNo) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry!</strong> UNIQUE APPLICATION ID doesn't match.<br>
Please enter again.
</div>";
} else if (strlen($contact) != 10 ) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> Contact No. should be of 10 digits.
</div>";
} else if ($contact!==$cContact) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry!</strong> Contact No. Doesn't match.
</div>";
} else if ($cEmail!==$Email) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry!</strong> Email Doesn't match.<br>
Please enter again.
</div>";
} else if ($stmt->rowCount() > 0) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry !</strong> Seat No is Already Registered.<br>
Please enter your correct Seat No OR <a class='btn btn-success btn-lg' href='login.php?days=".$days."'>Click here to login !</a>
</div>";
} else if ($standard == 'FYJC') {
if ($user->stud_personal_details($SeatNo, $FormNo, $SscAppNo, $Password, $contact, $code, $Email) &&
$user->stud_admission_details($SeatNo, $SscAppNo) &&
$user->stu_app($SeatNo, $code) &&
$user->Marks($SeatNo) ) {
$user->send_sms($SeatNo, $Password, $Email, $contact);
$msg = "<div class='alert alert-success' role='alert'>
<strong>Success!</strong> Your account is created.<br>
Password have been send on ".$contact." and also mailed at ".$Email."<br>
<a class='btn btn-success btn-lg' href='login.php?days=".$days."'>Click here to login !</a>
</div>";
} else {
$msg = "<div class='alert alert-danger' role='alert'>
<strong>Sorry !</strong> Something went wrong...<br>
Contact college office or IT Charge of College.
</div>";
}
}
}
}
如果出现某些错误或成功后,它将保持禁用状态。我的意思是说它应该在单击时保持禁用状态,但应在发生某些错误或成功时立即启用,以便用户可以再次填写表格并再次单击Submit。