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

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.