Jump to content

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


Ordinary_Shepp
Go to solution Solved by iarp,

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 ? 

Edited by Ordinary_Shepp
Link to comment
Share on other sites

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)
}
Edited by ginerjm
Link to comment
Share on other sites

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......

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.