PDA

View Full Version : Multiple submit button Problem


reub77
02-26-2004, 08:00 PM
I'm trying to send a form using the several submit buttons. Each button does something different. One button saves the information to the database, another sends the information via email to people. When I choose to send the information by e-mail I need to ask them to confirm their decision.

This all works however, I send the form elements to another page which in turn tries to determine which button you pressed and then carries out the necessary actions. I haven't yet been able to get everything working together harmoniously yet and my experience says it has something to do with how I'm determining which button on the form was pressed.

My form buttons look like this:


<input type='submit' name='sendEmail' value='Send E-mail' onClick='confirmit();return false'>

<input type='submit' name='saveDraft' value='Save Draft'>


The way I determine which button was pressed is this:


if($saveDraft!=""){
//perform actions
}
if($sendEmail!=""){
//perform actions
}


I was also wondering maybe there is a better way to determine which button was pressed. If there is a way to set a variable on the fly in an onClick event or something. If I can do that and send it in the form I could test for it on the other side. Does anybody know how to do this?

WebAsh
02-26-2004, 10:08 PM
What you could do, is have radio buttons, so to send the email have a radio button like <input type="radio" name="action" value="Email">
then the same for the Save to DB one, just change the value to SavetoDB or something, and then for wot $_POST["action"] contains in the PHP script...

And say the user forgets to select the correct radio button, well just add a javascript like:
<html><head>
<script language="javascript">
function selectradio(field) {
field.checked = true;
}
</script></head>

<body>
<form name="main" action=" form processor " method="post">
<input name="action" type="radio" value="email">
<input type="submit" name="EmailSend" value="Send Email!" onclick="selectradio(document.main.action[0])">

<input type="radio" name="action" value="save">
<input name="save" value="Save to Database" type="submit" onclick="selectradio(document.main.action[1])">
</form>
</body>
</html>


Make sense??? probably not, but ask for more if you dont!

reub77
02-26-2004, 10:11 PM
I don't really want to use radio buttons though. I'm trying to make this work almost like a real e-mail tool like Outlook. Buttons are the preferred method.

Jon Hanlon
02-26-2004, 11:01 PM
This issue was handled earlier today.
See http://www.htmlforums.com/showthread.php?s=&threadid=35373

You just need to change the anchor tags to be button onclicks.