tags:

views:

93

answers:

4
<?
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>

when the textarea is not null, the form should be submitted ($PHP_SELF) so i can get the value of the textarea. but before it is submitted there would be a dialog box that would appear. when the user clicks yes, he will be redirected to a different page. my problem is i don't know where to put the return true so that the page will be submitted in order for me to get the value of the textarea. i put the return false here:

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

when the textarea is null, the form will not submit and a different dialog box will appear.

where should i put the return true so that the page will only be submitted when the user input something in the textarea and after he clicks yes.

i have also included in the code where i have tried putting the return true but all failed. please help me. i've been trying to fix this for 3 days. :(

A: 

If it is a type="button" use the onclick event to control the action

andreas
A: 

button inputs are used for custom actions that are usually written in JavScript. That is, they do not submit a form like the Submit inputs. You can write a JavScript code that will submit the form for you OR navigate to a particular PHP page and achieve a similar effect.

Vincent Ramdhanie
A: 

If what you are asking is: How can I see in the POST response what button has been clicked?

Then I'm afraid you can't as only the name and value of the submit button that was used to submit the form is being listed in the $_POST data.

You can however achieve this using a hidden field and javascript. So you should do something similar to this:

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

So when the button is clicked the hidden field is set to true and when the form is submitted it appears in the $_POST array.

However, this doesn't make much sense if there are no other onclick events added to the button.

Maybe you should describe a little bit more what you are trying to do.

EDIT:

Since you updated your old question to a new one, this answer doesn't apply anymore.

André Hoffmann
A: 

Hello,
I wonder why you are using "button" and not "submit"? "button" comes in handy when you are using JavaScript, but it doesn't work with PHP. Furthermore, they makes no difference anyway.
If all that you want to do is to differentiate between the buttons, try giving them different names.
Hope that help

phunehehe