|
-
Dec 7th, 2005, 08:57 PM
#1
Thread Starter
Addicted Member
how to have 1 form with 2 submit buttons
hi all, how do you make 1 form with 2 submit buttons? I can show the buttons, of course, but how to handle the code?
I have a form that contains a number of items with checkboxes, and when the user clicks Delete button, the checked items will be deleted. It's no problem because I can just use the code <form action=delete.php ....>.
Now, the problem is, I want to make another button besides the Delete button. I want to have a Move button, so that when the user clicks the Move button, the checked items in the form will be moved to another category, not delete them.
I'm confused how to do that. You can't have a form with two actions (delete.php and move.php), right?
thanks for your help
-
Dec 8th, 2005, 01:23 AM
#2
Re: how to have 1 form with 2 submit buttons
The best way to do this is to submit to one script and create an action array form the submit buttons:
Code:
<input type="submit" name="action[delete]" vlaue="Delete" />
<input type="submit" name="action[move]" value="Move" />
You can then use the following code to check for what action is required:
PHP Code:
if (is_array($_POST['action'])) {
$action = array_keys($_POST['action']);
$action = $action[0];
}
swtich ($action) {
case 'move':
do_move();
break;
case 'delete':
do_delete();
break;
}
Some would say, just check the value the action variable, however, if you ever wanted to rename your submit button you will have to rewrite your code.
-
Dec 8th, 2005, 07:27 AM
#3
Re: how to have 1 form with 2 submit buttons
Actually, I tend to use <button> elements in these situations.
Code:
<button type="submit" name="action" value="move">Caption here</button>
<button type="submit" name="action" value="copy">Other caption here</button>
No ugly hacks, no rewriting.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 9th, 2005, 06:14 PM
#4
Hyperactive Member
Re: how to have 1 form with 2 submit buttons
Woopz, didn't read the topic good enough. (Deleted my reply )
Last edited by BramVandenbon; Dec 9th, 2005 at 06:25 PM.
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Dec 16th, 2005, 04:20 PM
#5
Fanatic Member
Re: how to have 1 form with 2 submit buttons
Here's anoher way to do it: http://thomasdamgaard.dk/pub/html/multiple-submit/
It uses a bit of java script to submit to different pages dependig on which button was pressed
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|