Log in

View Full Version : double submit button form



Hollywood
03-17-2010, 07:48 AM
i think i have seen something like this on this forum or the script section but can't seem to locate it now. how can i configure a form to have two or more submit button where every submit button will submit the form to a different action page. guess it is possible.
please any assistance will be appreciated. thanks in advance

djr33
03-17-2010, 08:18 AM
This thread has been moved to the HTML forum. Please only use the "Dynamic Drive scripts help" section for questions about specific Dynamic Drive scripts.
---


It is not possible to submit a form to multiple actions.
Multiple submit buttons are easy: just create more than one and they will all work.
It is possible to use Javascript to dynamically change the URL of the action for the form upon clicking a button, but this will not always work because some users will disable Javascript.

Because of all this, the best way to approach this is to give the submit buttons values (names and values, actually) so that then you can identify which button was pressed when the form was submitted using serverside code like PHP. Then that serverside code can take that information and do multiple things. This doesn't allow for actually using different pages, but using serverside code you can do different operations depending on the input.

YasminTiara
03-17-2010, 04:05 PM
I sometimes forget how careful you have to be when designing applications for end users. As a developer, I would never think to double click a submit button on a web form. I also understand that queries and form submissions sometimes take a few seconds and am happy to give them a little time. Some end users on the other hand, seem to subscribe to the "I'll click until something happens" philosophy. They'll click the submit button, and if the form doesn't immediately go away, they'll either click the submit button again or better yet, they'll try double clicking it.

Obviously the first order of business is to make sure your form submissions are processed as quickly as possible. Do your best to optimize those database queries and load test your site to be sure your code scales well before you go live. Another tip is to use the Response.Flush() command on the page that does the processing so that any buffered output is sent to the client immediately. That way the browser doesn't have to wait until the whole page is processed in order to start rendering the result page.

Unfortunately, even after these optimizations, there are still times when things aren't as snappy as they should be. Whether it's plain old network latency or you've simply got a user that's accessing your site via dial-up or a cell phone connection, we still can't have them double clicking (and sometimes even triple clicking) our submit button. If they do, we're likely to end up with duplicate entries in our database or shipping duplicate orders to the same person. Either way, duplicate data costs us time and/or money.

Wouldn't it be nice if once a user clicked the button, we could "turn it off" so that they couldn't click it again? Guess what... we can do just that and the best part is that it's actually really easy!

Take a look at the sample HTML below:

<form action="ProcessFormData.asp">
<input type="submit" id="btnSubmit" value="Submit"
onclick="this.disabled=true;this.value='Submitting...';
this.form.submit();"
/>
</form>

The secret is in the line I've highlighted in red. It's a short piece of client-side Javascript that is called via the OnClick event of the submit button. The code does three things:

1. First it disables the button so that the user can't click it again.
2. Then it changes the button's text so that the user gets some feedback and is informed of what's going on.
3. Finally it submits the form for processing.

So you can get an idea of what it'll look like, I'm including a sample below. There's no form attached to it so nothing gets submitted, but you'll at least get an idea of how it works. I've added a Reset button which will re-enable the submit button after you're clicked it so you can try it a few times if you'd like.

djr33
03-17-2010, 04:10 PM
Read the original question more clearly: the question is about using TWO different submit buttons, not preventing double submissions.

Hollywood
03-20-2010, 01:54 AM
first, I'm very sorry i thought i was in the right place to ask that kind of question. the fact is that i actually encountered the problem in my coldfusion code i did not know where to post it and as you all know dynamicforum does not currently (to the best of my knowledge) have any section for coldfusion so i thought if i could get a clue form that post, i will be able to set my work in motion. but that is it. i just have to figure out a way to solve the problem. thanks again for the response.
Note: i actually said a form with multiple submit buttons not disabling a submit button after a click so as to discourage clicking on it twice. and talking about disabling a button after first click, what stops the user from refreshing the page the clicking on it again and again for as long as he or she wants. they just do it to give either your database or your site a whole lot of work to do or for personal reasons or pleasure. well that is by the way.

djr33
03-20-2010, 08:39 PM
"Dynamic Drive scripts" is specifically for scripts hosted on the website here and getting them to work. Unless you have a question directly about using/modifying them (in other words, you will have a link to one of the pages on this site), then your question best belongs in one of the other forums.
If you're unsure about where it should go (such as with this post), then just think about the general type of code being used-- html, right? HTML forms, so it's an html question. If it is the wrong place, a mod can move it, so don't worry. If you are using something completely different from other code here, then you can post it in the "other" section or "looking for a script or service" section.
Now to the question---


The basic method should apply in coldfusion as well, though I don't know the details of using that. Coldfusion is just a way to write html, so the end result in the browser will be the same. Of course parsing this on the server will be different, so maybe you will need specific help with that, but in theory it should be similar to doing it in PHP.

The short answer to your question is that there is no way to do this, except that you can tell which button was clicked, so if you can then take from that the information you need, you can effectively have two different results. But from HTML alone there's no way to do this.