Jump to content

Submit buttons


Wstar

Recommended Posts

I can not find out whats wrong here.  It's most likely something small that I've over looked.  I have multiple submit buttons on a forum using the following code:

 

                  
                 if ($action=='edit') {
                    echo '<input type="submit" name"update" value="Update">' . '   ';
                    echo '<input type="submit" name"cancel" value="Cancel">';
                  } else {
                    echo '<input type="submit" name"delete_confirmed" value="Delete">' . '   ';
                    echo '<input type="submit" name"update" value="Update">' . '   ';
                    echo '<input type="submit" name"cancel" value="Cancel"></form>';
                  }

 

At the top of the .php file I have the following:

 

if(isset($cancel)){
  $action='';
} elseif(isset($add)) {
  $message="Files stored successful.";
} elseif(isset($delete_confirmed)) {
  $message="Files has been deleted.";
} elseif(isset($update)) {
  $message="Files stored and updated successful.";
}

 

Now, when the forum is submitted by hitting the add button, nothing is stored in $message.  Later in the code (start of a table for a header) I have:

 

<?=$message?>

 

My form declaration is:

 

<form enctype="multipart/form-data" method="post" action="news.php">

 

Why are my submit buttons NOT working?

Link to comment
https://forums.phpfreaks.com/topic/44002-submit-buttons/
Share on other sites

Depending on what variables you've declared set or php version you're running,trying this might help:

 

if(isset($_REQUEST['cancel'])){
  $action='';
} elseif(isset($_REQUEST['add'])) {
  $message="Files stored successful.";
} elseif(isset($_REQUEST['delete_confirmed'])) {
  $message="Files has been deleted.";
} elseif(isset($_REQUEST['update'])) {
  $message="Files stored and updated successful.";
}

 

Also:

 

<?php echo($message); ?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/44002-submit-buttons/#findComment-213655
Share on other sites

Thanks for the quick replies.  I know its not a problem with <?=$message?> because I've just tried this.

 

if(isset($_REQUEST['test1'])){
  echo "Test 1";
} elseif(isset($test2)) {
  echo "Test 2";
} 

<form enctype="multipart/form-data" method="post" action="news.php">
  <input type="submit" name"test1" value="Test 1">
  <input type="submit" name"test2" value="Test 2">
</form>

 

Nothing gets echo'ed in either case.  I'm just not understanding this problem.

Link to comment
https://forums.phpfreaks.com/topic/44002-submit-buttons/#findComment-213661
Share on other sites

Still nothing.  Here is my form code in html.

<form enctype="multipart/form-data" method="post" action="news.php">
  <input type="submit" name"test1" value="Test 1">
  <input type="submit" name"test2" value="Test 2">
</form>

 

Here is the php code for submitting.  I've tried doing each of these (one at a time):

 

if($_REQUEST['test1']){
  echo "It WOrked!";
} else {
  echo "It DIDNT WOrked!";
}

AND

 

if(isset($_REQUEST['test1'])){
  echo "It WOrked!";
} else {
  echo "It DIDNT WOrked!";
}

AND

 

if(isset($test1)){
  echo "It WOrked!";
} else {
  echo "It DIDNT WOrked!";
}

 

Still no luck.

Link to comment
https://forums.phpfreaks.com/topic/44002-submit-buttons/#findComment-213670
Share on other sites

No need for shame m8, we all waste hours this way from time to time :-)

You just need to get better in trying to isolate the problem step by step. I copy/pasted your code, and when I didn't get it to work the way you wanted it to, i changed the method to GET. I then got "?test1" in the url. Problem was then easily found :-)

Link to comment
https://forums.phpfreaks.com/topic/44002-submit-buttons/#findComment-213682
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.