Jump to content

[SOLVED] Multiple Submit buttons


dezkit

Recommended Posts

I have this script that i made:

<?php
$submit = $_POST["submit"];
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];

if(isset($submit)){

if($submit == "Create"){
  echo "$firstname $lastname has been created in the database.";
} 
elseif($submit == "Delete"){
  echo "$firstname $lastname has been cleared from the database.";
}

} else {
?> 
<form action="" method="post">
<table>
<tr>
<td>First name:
<td><input type="text" name="firstname">
<tr>
<td>Last name:
<td><input type="text" name="lastname">
<tr>
<td colspan=2>
<input type="submit" name="submit" value="Create">
<input type="submit" name="submit" value="Delete">
<input type="reset" name="reset" value="Reset">
</table>
</form>
<?php
}
?>

 

and i was wondering if there is a way for that if people press enter, the form doesn't submit.

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

This has to be javascript so moving to js forum.

 

Pressing enter causes the default submit button to be clicked (in this case "create") so you can use mouse up to see if it really was clicked.

 

 

<?php
echo '<pre>', print_r($_POST, true), '</pre>';

?>
<html>
<head>
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>sample</title>
<meta name="author" content="barand">
<link rel="shortcut icon"  href="">
<meta name="creation-date" content="08/30/2008">

<script type='text/javascript'>
    var buttonClicked = false;
    
    function checkButtonClicked()
    {
        return buttonClicked;
    }
</script>

</head>
<body>
<form action="" method="post" onsubmit='return checkButtonClicked()'>
<table>
<tr>
<td>First name:
<td><input type="text" name="firstname">
<tr>
<td>Last name:
<td><input type="text" name="lastname">
<tr>
<td colspan=2>
<input type="submit" name="btnsubmit" value="Create" onmouseup='buttonClicked=true'>
<input type="submit" name="btnsubmit" value="Delete" onmouseup='buttonClicked=true'>
<input type="reset" name="reset" value="Reset">
</table>
</form>
</body>
</html>

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.