assume there are 2 forms (form1 and form2), both forms contain button named "send";
if only one form, it is easy to identify if the button is pressed by code:
if(isset($_POST['send']))//works
{
}
but there are 2 buttons with same name in 2 forms, can we identify a button using its parent?
E.g.
if(isset($_POST['window.document.form1.send']))
{
}
code above is not working, I need correct code.
thanks
how to identify if a button is pressed?
Moderator: General Moderators
-
php12342005
- Forum Commoner
- Posts: 79
- Joined: Mon Mar 21, 2005 3:35 am
-
dyonak
- Forum Commoner
- Posts: 56
- Joined: Wed Jun 22, 2005 10:22 am
- Location: Minneapolis, MN
- Contact:
You need to set the name parameter for each of your submit buttons on your forms to unique values: foosubmit and barsubmit for example.
Code: Select all
//Form 1 handler
if isset ($_POST['foosubmit']){
do 'this';
}
//Form 2 handler
if isset ($_POST['barsubmit']){
do 'this';
}If you want to separate between them, just use a different "name" attribute for each of them..
Or use a hidden variable to distinguish them
Code: Select all
<input type='submit' name='send1' Value='Send'/>
<input type='submit' name='send2' Value='Send'/>Code: Select all
<form action="e;"e; method="e;post"e;>
<input type='submit' name='send' value='Send'/>
<input type='hidden' name='form' value='1'/>
</form>
<form action="e;"e; method="e;post"e;>
<input type='submit' name='send' value='Send'/>
<input type='hidden' name='form' value='2'/>
</form>Use a hidden field in both the forms
And check for $_POST['hsend']
Believe but in rare situations, the button name never gets sent over GET or POST.
Code: Select all
<form...>
<input type="e;hidden"e; name="e;hsend"e; value="e;1"e;/>
...
<input type="e;submit"e; name="e;send"e; value="e; Send "e;/>
</form>
.......
<form...>
<input type="e;hidden"e; name="e;hsend"e; value="e;2"e;/>
...
<input type="e;submit"e; name="e;send"e; value="e; Send "e;/>
</form>Believe but in rare situations, the button name never gets sent over GET or POST.