我剛纔發現isset功能不再工作在我的登錄和註冊形式的PHP isset功能。我很奇怪,所以我解開了我最近所做的一切,看它是否造成了它,但沒有運氣。如果我刪除isset並用此替換;對提交檢查工作不
if($_SERVER['REQUEST_METHOD'] == "POST"){
它的工作原理!但是我在一個頁面上有兩個表單,所以我需要檢查哪一個被提交。
這裏的isset功能:
if (isset($_POST['submit_login'])) {
而只是讓你知道它有正確的名稱提交按鈕;
<input type="submit" name="submit_login" value="Login" class="buttonClassic"/>
的一個註冊表單是完全一樣的,但用的名字submit_reg
。
形式:
<form action="<?php echo htmlentities('Login'); ?>" method="post" id="login">
<p class="p1">Already signed up? Log in</p><hr/>
<label for="email">Your email address </label><input type="email" required name="email" placeholder="Email" class="text" id="email">
<label for="password">Your password </label><input type="password" name="pass" required placeholder="Password" class="text" id="password">
<center><input type="submit" name="submit_login" value="Login" class="buttonClassic"/></center>
<div class="center-align-text">
<p class="p3"><a href="passreset.html">Forgotten your password?</a></p>
</div>
</form>
註冊表單:
<form action="<?php echo htmlentities('Login'); ?>" method="post" id="register" >
<p class="p1">New to NBS? Sign up, it's free!</p><hr/>
<label for="reg_email">What's your email address? </label><input type="email" name="email" required placeholder="Email" class="text" id="reg_email">
<label for="reg_password">Choose a password </label><input type="password" required name="pass" placeholder="Password" class="text" id="reg_password">
<label for="reg_password2">Re-type password </label><input type="password" required name="pass2" placeholder="Re-type password" class="text" id="reg_password2">
<input type="checkbox" name="subscribed" value="subscribed" id="subscribed"><label for="subscribed">Yes, send me email updates from NewBorn Sounds. </label>
<br/>
<input type="checkbox" required="flag" name="terms" value="ticked" id="terms"><label for="terms">I agree to the <a href="Terms">terms & conditions</a>.</label>
<center><input type="submit" name="submit_reg" value="Sign Up" class="buttonClassic"></center>
</form>
如果您有什麼需要更多就罵!
哦,我知道我可以只提交表單到外部的PHP腳本,但我並不特別想這樣做,因爲我想在用戶輸入錯誤將被輸出到同一頁。我知道我可以使用ajax,但我試圖將javascript作爲附加組件,而不是減少沒有js的用戶體驗。
HTML全文:
<div id="login_form_wrapper">
<form action="Login" method="post" id="login" novalidate="novalidate">
<p class="p1">Already signed up? Log in</p><hr>
<label for="email">Your email address </label><input type="email" required="" name="email" placeholder="Email" class="text" id="email">
<label for="password">Your password </label><input type="password" name="pass" required="" placeholder="Password" class="text" id="password">
<center><input type="submit" name="submit_login" value="Login" class="buttonClassic"></center>
<div class="center-align-text">
<p class="p3"><a href="passreset.html">Forgotten your password?</a></p>
</div>
</form>
<form action="Login" method="post" id="register" novalidate="novalidate">
<p class="p1">New to NBS? Sign up, it's free!</p><hr>
<label for="reg_email">What's your email address? </label><input type="email" name="email" required="" placeholder="Email" class="text" id="reg_email">
<label for="reg_password">Choose a password </label><input type="password" required="" name="pass" placeholder="Password" class="text" id="reg_password">
<label for="reg_password2">Re-type password </label><input type="password" required="" name="pass2" placeholder="Re-type password" class="text" id="reg_password2">
<input type="checkbox" name="subscribed" value="subscribed" id="subscribed"><label for="subscribed">Yes, send me email updates from NewBorn Sounds. </label>
<br>
<input type="checkbox" required="flag" name="terms" value="ticked" id="terms"><label for="terms">I agree to the <a href="Terms">terms & conditions</a>.</label>
<center><input type="submit" name="submit_reg" value="Sign Up" class="buttonClassic"></center>
</form>
</div>
'print_r($ _ POST);' – str
出於好奇,你有兩個單獨的嵌套表單嗎? – Fabio
@Fabio yes表單完全獨立 –