Jump to content

How to two submit button on one form with two different action


Ordinary_Shepp

Recommended Posts

How can I get two submit button on one form with two different action?

<?php
	require_once 'func.php';
	connect() ;

?>

<!DOCTYPE html>
<html>
	<head>
	</head>
	<body>
		<header> <h1 align='center'>student</h1></header>
		<form method="post" action="process.php" enctype="multipart/form-data">
			<table>
		
			<tr> <td>     </td> <td><input type="submit" value="Submit"></td></tr>
			</table>
		</form>
	</body>
</html>

Here is a code segment. I want to get two button "submit" and "go back" which should take me to the "process.php" and "index.php" .  Thanks in advance for your help. And is there any way to call a php function by clicking a submit button ? 

Not to confuse the issue, but when a submit button is passed to the script it is not the "ID" that you look for but the "name" that you look for and in order to distinguish between multiple buttons with the same name you look for the "value".

 

ex.

<form method="POST">
<input type='submit' name='btn' value="Submit">
<input type='submit' name='btn' value="Cancel">
</form>

In you php you would then do:

if ( !isset($_POST['submit']))
{
    (handle no submit yet)
}
//  got a click from the form
$btn = $_POST['submit'];
if ($btn == "Submit")
{
( do the submit logic)
}
if ($btn == "Cancel")
{
  (do the cancel logic)
}

If anyone is still reading this I have to correct my code above.  In the PHP code one should be checking $_POST['btn']   and NOT $_POST['submit'].  Don't know what I was thinking when I dashed off that response.

 

Two major errors in one hour today.  Must need a rest or something......

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.