2009-09-12 49 views
0
<? 
session_start(); 
include("connection.php"); 

if($_POST['continue']) 
{ 
    $x=$_POST['rules']; 
} 
?> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link type="text/css" href="jquery-ui-1.7.2.custom.css" rel="stylesheet" /> 
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> 
    <script type="text/javascript" src="jquery-1.3.2.js"></script> 
    <script type="text/javascript" src="ui/ui.core.js"></script> 
    <script type="text/javascript" src="ui/ui.draggable.js"></script> 
    <script type="text/javascript" src="ui/ui.resizable.js"></script> 
    <script type="text/javascript" src="ui/ui.dialog.js"></script> 
    <script type="text/javascript" src="external/bgiframe/jquery.bgiframe.js"></script> 

    <script type="text/javascript"> 

    function haha(form) 
    {  
     if(form.rules.value=='') 
     { 
      printToPage('output','Please enter the rules.','text') 
      hello(); 
      return false;    
     } 
     else 
     { 
      myRedirect(); 
      return false; 
     } 
    } 

    $(function() 
    { 
     $("#dialog").dialog({ 
      autoOpen: false, 
      bgiframe: true, 
      resizable: false, 
      draggable: false, 
      height:10, 
      width:340, 
      modal: true, 
      overlay: 
        { 
         backgroundColor: '#000', 
         opacity: 0.5 
        }, 
      buttons: 
        { 
         'No': function() 
         { 
          window.location = "so-rules.php"; 
          return true; 
         }, 
         'Yes': function() 
         { 
          window.location = "so-rules.php"; 
          return true; 
         } 
      } 
     }); 
    }); 

    function myRedirect() 
    { 
     $("#dialog").dialog('open'); 
     return true; 
    } 

    $(function() 
    { 
     $("#dialog2").dialog 
      ({ 
      autoOpen: false, 
      bgiframe: true, 
      modal: true, 
      resizable: false, 
      draggable: false, 
      height:160, 
      width:260, 
      buttons: 
        { 
         Ok: function() 
         { 
          $(this).dialog('close'); 
         } 
        } 
     }); 
    }); 

    function hello() 
    { 
     $("#dialog2").dialog('open'); 
    } 

    function getElem(id) 
    { 
     return document.all ? document.all(id) : 
     document.getElementById ? document.getElementById(id) : 
     document.layers ? document.layers[id] : 
     null; 
    } 

    function printToPage(id,content,classname) 
    { 
     var el = getElem(id); 

     if (!el) return; 

     if (el.style) 
     { 
      el.innerHTML = content; 

      if (classname) el.className = classname; 
     } 
     else if (el.document) 
     { 
      var SPANstr = (classname) ? '<span class="' + classname + '">' : '<span>'; 
      el.document.write('haha'); 
      el.document.close(); 
     } 
    } 
    </script> 

</head> 

<body> 


    <td height="" bgcolor="#fafb91"><form onsubmit='return haha(form)' id="form" name="form" method="post" action="<? echo $PHP_SELF; ?>"> 
      <p class="style16"> 
      <div align="left"> 

      <p><span class="style5">Rules:</span> 
       </p> 

      <p> 
       <textarea name="rules" rows="7" cols="49"></textarea> 

       <br /> 
       <? echo "X: ".$_SESSION['x']; ?> 
      </p> 
      <div id="dialog" title="Attention"> 
      <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Is the judge/speaker/facilitator from UST?</p> 
      </div> 

      <div id="dialog2" title="Attention"> 
      <p> 
      <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 0 50px 0;"></span> 
      Please enter the rules. 
      </p> 
      </div> 

      <p><input type="submit" name="continue" id="continue" value="Continue"> 
      <span id="output"></span> 

</body> 
</html> 

當textarea不爲空時,表單應該被提交($ PHP_SELF),這樣我就可以得到textarea的值。但是在提交之前,會出現一個對話框。當用戶點擊是時,他將被重定向到不同的頁面。我的問題是我不知道在哪裏放置返回'真',以便頁面將被提交以便我獲得textarea的價值。我把這個返回'假'在這裏:Javascript,jQuery,PHP問題。

if(form.rules.value=='') 
{ 
    printToPage('output','Please enter the rules.','text') 
    hello(); 
    return false;  
} 

當textarea爲空,表單將不會提交,並會出現一個不同的對話框。我應該在什麼地方將返回值設置爲「真」,以便只有在用戶在textarea中輸入內容並點擊「是」之後纔會提交頁面。

我已經發布了代碼,我試圖在返回'真正'沒有成功。

回答

0

如果它是一個類型=「按鈕」使用onclick事件來控制

0

按鈕輸入用於其通常用JavaScript編寫自定義操作的動作。也就是說,他們不提交表單,如提交輸入。您可以編寫一個JavaScript代碼來爲您提交表單,或導航到特定的PHP頁面並獲得類似的效果。

0

如果你問的是:我怎樣才能看到POST響應按鈕已被點擊?

那麼恐怕你不能這樣做,因爲只有用於提交表單的提交按鈕的名稱和值已列在$_POST數據中。

但是,您可以使用隱藏字段和JavaScript來實現此目的。所以,你應該做一些與此類似:

<input type="button" id="continue" value="Continue" onclick="document.getElementById('hiddenContinue').value = 'true';" /> 
<input type="hidden" name="continue" id="hiddenContinue" value="false" /> 

因此,當按鈕被點擊隱藏字段設置爲true,當表單提交它出現在$_POST陣列英寸

但是,如果沒有其他onclick事件添加到按鈕,這沒什麼意義。

也許你應該多描述一下你正在嘗試做的事情。

編輯

既然你的老問題,更新到一個新的,這個答案已經不適用。

0

我想知道爲什麼你使用「按鈕」而不是「提交」?當您使用JavaScript時,「按鈕」會派上用場,但它不適用於PHP。而且,它們無論如何也沒有區別。
如果您想要做的只是區分按鈕,請嘗試給他們不同的名稱。
希望幫助