2012-10-06 27 views
0

我不希望這段代碼在頁面自動運行時運行。爲什麼這段代碼仍在運行,儘管我已經允許這樣做

//There was an identical id and request is somewhat real. (Still possible of a lucky guess) 
    if($array['isbeingwritten'] == 1) 
    { 
     //The article is already being written. 
     echo '<script type="text/javascript">alert("That article is being written. Someone beat you to it. You will now be redirected.");</script>'; 
     echo '<script type="text/javascript">window.location.href="write.php";</script>'; 
    } 

所以,我已經做到了這一點:

if(!isset($_POST['submit'])) 
{ 
    //There was an identical id and request is somewhat real. (Still possible of a lucky guess) 
    if($array['isbeingwritten'] == 1) 
    { 
     //The article is already being written. 
    echo '<script type="text/javascript">alert("That article is being written. Someone beat you to it. You will now be redirected.");</script>'; 
    echo '<script type="text/javascript">window.location.href="write.php";</script>'; 
    } 
} 

這是行不通的。它仍然按下提交後運行該代碼!這裏是我的形式:

  <form method="post" id="writearticle" action=""> 
       <textarea rows="30" cols="85" id="articlecontent" name="content" placeholder="Write the article here. Try to abide by the instructions and keywords provided." onkeyup="checkWordCount();" ></textarea> 
       <br />  
       <input type="submit" id="submit" name="submitarticle" value="Submit Article" class="submit" disabled />  

       <br /><br /><br /><br /><br /> 
      </form> 
+0

'NAME =「submitarticle」'你有沒有名爲「提交」領域,因此它永遠不會被設置。 – Wiseguy

+0

謝謝。我總是很困惑我是否應該使用id或name .. – KriiV

回答

4

更改代碼if(!isset($_POST['submit'])) to if(!isset($_POST['submitarticle']))