Page 1 of 1
how to identify if a button is pressed?
Posted: Tue Jul 26, 2005 7:23 am
by php12342005
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
Posted: Tue Jul 26, 2005 7:28 am
by dyonak
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';
}
Posted: Tue Jul 26, 2005 7:30 am
by timvw
If you want to separate between them, just use a different "name" attribute for each of them..
Code: Select all
<input type='submit' name='send1' Value='Send'/>
<input type='submit' name='send2' Value='Send'/>
Or use a hidden variable to distinguish them
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>
Posted: Tue Jul 26, 2005 7:30 am
by anjanesh
Use a hidden field in both the forms
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>
And check for $_POST['hsend']
Believe but in rare situations, the button name never gets sent over GET or POST.