Page 1 of 1

Post Var. Not Getting Passed To Switch Statement

Posted: Mon Mar 22, 2004 10:05 am
by Crashin
I've got the following JS function to handle form cancellations:

Code: Select all

// function to cancel
function cancel_form(formName) {
  alert(formName.name);
  formName.submit();
}
And I've got the following cancel button on the form:

Code: Select all

<input type="button" name="submitIt" value="Cancel" onclick="return cancel_form(this.form)">
And here is my switch statement:

Code: Select all

<?php
// begin switch statment to handle POST request
switch ($_POST['submitIt']) {
  case 'Cancel': // if it is being cancelled
    echo "submitIt is CANCEL";
    break; // ---------- end of cancel case ----------
  
  case 'Submit': // if creating a new one
    echo "submitIt is SUBMIT";
    break; // ---------- end of create case ----------
  	
  default:
    echo "submitIt is NOTHING";
}
?>
However, I'm getting:
Notice: Undefined index: submitIt in c:\program files\apache group\apache\htdocs\projects\process_customer_suggestion.php on line 42
submitIt is NOTHING
upon submittal. What gives? I've read through php.net about switch statements, but nothing seems wrong there. :?

Posted: Mon Mar 22, 2004 10:13 am
by magicrobotmonkey
I'm not sure if submit buttons pass their value that way. In your javascript do an alert(submitIt.value) and see what it shows. Read through this thread: viewtopic.php?t=19723

Posted: Mon Mar 22, 2004 10:14 am
by CoderGoblin
Not sure but try adding a semicolon on your input statement....

Code: Select all

&lt;input type="button" name="submitIt" value="Cancel" onclick="return cancel_form(this.form);"&gt;
to check PHP value try ...

Code: Select all

if (isset($_POST['submitIt'])) {
  switch ($_POST['submitIt']) { 
    ....
  }
} else {
  echo(" !! Could not read value of submitIt ");
}
To confirm ... there doesn't seem to be anything wrong with the switch so it appears you are not passing the POST value, check javascript possibilities.