2009-09-12 2 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> 

텍스트 영역이 null이 아닌 경우 양식을 제출 ($ PHP_SELF)하여 텍스트 영역의 값을 가져올 수 있습니다. 그러나 제출되기 전에 대화 상자가 나타납니다. 사용자가 예를 클릭하면 다른 페이지로 리디렉션됩니다. 내 문제는 어디에 텍스트 섹션의 가치를 얻을 수 있도록 페이지를 제출할 수 있도록 반환 '사실'을 어디에 넣어야할지 모르겠다. 여기에 'false'가 반환됩니다.Javascript, jQuery, PHP 문제가 있습니다.

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

텍스트 영역이 null이면 양식이 제출되지 않고 다른 대화 상자가 나타납니다. 사용자가 텍스트 영역에 무엇인가를 입력하고 '예'를 클릭 한 후에 만 ​​페이지가 제출 될 수 있도록 반환 값을 'true'로 지정해야합니다.

나는 성공없이 'true'를 반환하려고 시도한 코드를 게시했습니다.

답변

0

버튼 입력은 일반적으로 자바 스크립트로 작성된 사용자 지정 작업에 사용되는 동작을 제어 할 수 onclick 이벤트를 사용하는 경우. 즉, 제출 입력과 같은 양식을 제출하지 않습니다. 양식을 제출하거나 특정 PHP 페이지로 이동하여 유사한 효과를 얻을 수있는 JavaScript 코드를 작성할 수 있습니다.

0

당신이 묻는 질문은 : 어떻게하면 POST 응답에서 어떤 버튼을 클릭하면 볼 수 있습니까?

그러면 양식을 제출하는 데 사용 된 제출 버튼의 이름과 값만이 $_POST 데이터에 나열되어 있기 때문에 두려워 할 것입니다.

그러나 숨겨진 필드와 자바 스크립트를 사용하여이를 수행 할 수 있습니다. 버튼이 숨겨진 필드를 클릭 그래서

<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

"제출"하지 않고 "버튼"을 사용하는 이유가 궁금합니다. "버튼"은 자바 스크립트를 사용할 때 편리하지만 PHP에서는 작동하지 않습니다. 게다가, 그들은 어쨌든 아무런 차이가 없습니다.
버튼 사이를 구분하려면 모두 다른 이름을 지정하십시오.
도움이 되길 바랍니다.