2009-09-12 50 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。而且,它们无论如何也没有区别。
如果您想要做的只是区分按钮,请尝试给他们不同的名称。
希望帮助