Hey everyone, I’m working on an editor for a blog and part of the functionality is to be able to, in the same form, either save changes, delete the entry or cancel. Now, i can think of a dozen ways to do this in javascript :D, but i was wondering if there was any easy, non-complicated way to do this purely in HTML, with some attribute or something like that.
so in other words i’d like to have multiple submit buttons in the same form point to different actions. If its not possible without Javascript, i don’t have a problem with doing that, if thats the case just say so.
Give some extra thought on which is the first one. If the user is in the text field and hits enter, the system will assume the first submit button was hit.
You might find it easier to give all the submit buttons the same name but different values. Then check in your php code which value was sent which will tell you which submit button was clicked.
<?php
if (isset($_POST['btnSubmit'][0])) {
switch (strtolower($_POST['btnSubmit'][0])) {
case 'save':
echo '<h1>Save button was clicked</h1>';
break;
case 'delete':
echo '<h1>Delete button was clicked</h1>';
}
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title></title>
</head>
<body>
<form action="#" method="post">
<input type="submit" name="btnSubmit[]" value="Save" />
<input type="submit" name="btnSubmit[]" value="Delete" />
</form>
</body>
</html>