Determining which form submit button pressed
Moderator: General Moderators
-
benchmarkman
- Forum Newbie
- Posts: 6
- Joined: Tue Apr 24, 2007 8:01 pm
Determining which form submit button pressed
I have a page with an unknown amount of form submit buttons. Is there a way to determine which submit button was pressed?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
benchmarkman
- Forum Newbie
- Posts: 6
- Joined: Tue Apr 24, 2007 8:01 pm
I got it working.
I had already done the different names I was not sure how to Identify which button had been pressed. I used a while loop and the isset method in the page I was submitting to.shiznatix wrote:name each submit button differently or have a hidden field in each form with an identifier so you will know which form was submitted
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Clicking enter doesn't count as using the submit button? Are you sure? As far as I know, pressing enter in a form counts as using that particular form's submit button.Jcart wrote:I would use a hidden input field, as the submit button is not always sent (e.g. the user hits enter instead of clicking the submit button)
As far as I know, hitting Enter will be the same as clicking the next submit button (on the HTML code). So basically if your structure is something like:
<form field>
<submit1>
<submit2>
Enter will be the same as <submit1>.
Can't be absolutely sure this is the exact same behaviour for every browser though, some testing is recommended.
<form field>
<submit1>
<submit2>
Enter will be the same as <submit1>.
Can't be absolutely sure this is the exact same behaviour for every browser though, some testing is recommended.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Ask and you shall receive.
Firefox 1.5
IE 7
Code: Select all
<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
<form action="#" method="POST">
<input type="text" name="foo1" value="bar1">
<input type="submit" name="foo2" value="bar2">
</form>Code: Select all
Array
(
[foo1] => bar1
[foo2] => bar2
)Code: Select all
Array
(
[foo1] => bar1
)
Last edited by John Cartwright on Mon Apr 30, 2007 1:49 pm, edited 1 time in total.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
So, checking isset($_POST['this_forms_button']) isn't IE friendly? God... I was unaware.
I test a little in IE, but for the most part, I only test stylistic issues. I didn't know IE couldn't properly submit forms. So can you prevent someone from submitting one form to another page through altering the HTML? Is there any way to cope for some malicious user that really wants to mess around with stuff in the HTML?
Maybe JavaScript...?
I test a little in IE, but for the most part, I only test stylistic issues. I didn't know IE couldn't properly submit forms. So can you prevent someone from submitting one form to another page through altering the HTML? Is there any way to cope for some malicious user that really wants to mess around with stuff in the HTML?
Maybe JavaScript...?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
All you can do is validate. A user can easily gank the source of your form (View Source) and change whatever they want in it (like maxlength properties), strip out any Javascript validation and process it to your site without you knowing about it really.
PS Check the post array in IE when using an image submit button and clicking on it to submit. You'd like that a lot if you like the fact that it doesn't send the button when hitting enter in a form.
PS Check the post array in IE when using an image submit button and clicking on it to submit. You'd like that a lot if you like the fact that it doesn't send the button when hitting enter in a form.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: