By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

Getting button pressed

P: n/a
Hi

It is late and I am tired. I cannot remember how to check which of my
buttons on the form was pressed. There are all submit's.

Like

echo "P=".$_POST['btn_post1']; // and eventually using isset()

But how was it it was?
Aug 25 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
jodleren wrote:
Hi

It is late and I am tired. I cannot remember how to check which of my
buttons on the form was pressed. There are all submit's.

Like

echo "P=".$_POST['btn_post1']; // and eventually using isset()

But how was it it was?
Unless you use javascript with 'onclick' to set a hidden variable, I
don't think there is a way of working out which submit button was pressed.

Aug 25 '08 #2

P: n/a
jodleren wrote:
Hi

It is late and I am tired. I cannot remember how to check which of my
buttons on the form was pressed. There are all submit's.

Like

echo "P=".$_POST['btn_post1']; // and eventually using isset()

But how was it it was?
The contents of $_POST['btn_post1'] will contain the contents of the
value= parameter of the pressed button.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 25 '08 #3

P: n/a
If I have a form

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">

<input type="submit" name="sub" value="Submit1" />
<input type="submit" name="sub" value="Submit2" />

</form>
I could check which one was submitted using the value.

e.g.

if (isset($_GET['sub']) && $_GET['sub'] == 'Submit1'){

echo 'Submit1 was pressed';

} elseif (isset($_GET['sub']) && $_GET['sub'] == 'Submit2'){

echo 'Submit2 was pressed';

}
Aug 25 '08 #4

P: n/a
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">

That should be <?php echo $_SERVER['PHP_SELF'] ?of course, before
anyone comments... ;-)
Aug 25 '08 #5

P: n/a
..oO(The Natural Philosopher)
>jodleren wrote:
>Hi

It is late and I am tired. I cannot remember how to check which of my
buttons on the form was pressed. There are all submit's.

Like

echo "P=".$_POST['btn_post1']; // and eventually using isset()

But how was it it was?
Unless you use javascript with 'onclick' to set a hidden variable, I
don't think there is a way of working out which submit button was pressed.
Of course there is. Just give it a name and its value will be sent to
the server if you activate the button.

Micha
Aug 26 '08 #6

P: n/a
Michael Fesser wrote:
.oO(The Natural Philosopher)
>jodleren wrote:
>>Hi

It is late and I am tired. I cannot remember how to check which of my
buttons on the form was pressed. There are all submit's.

Like

echo "P=".$_POST['btn_post1']; // and eventually using isset()

But how was it it was?
Unless you use javascript with 'onclick' to set a hidden variable, I
don't think there is a way of working out which submit button was pressed.

Of course there is. Just give it a name and its value will be sent to
the server if you activate the button.
Oh? Never thought thought of naming a _submit_ button..

I gave up on em..they look too clunky..I always use javascript instead
on custom buttons..
Micha
Aug 26 '08 #7

P: n/a
On 25 Aug, 22:28, macca <ptmcna...@googlemail.comwrote:
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">

That should be <?php echo $_SERVER['PHP_SELF'] ?of course, before
anyone comments... * *;-)
Or even just:
<form action="" method="get">
Aug 26 '08 #8

P: n/a
..oO(The Natural Philosopher)
>Michael Fesser wrote:
>.oO(The Natural Philosopher)
>>Unless you use javascript with 'onclick' to set a hidden variable, I
don't think there is a way of working out which submit button was pressed.

Of course there is. Just give it a name and its value will be sent to
the server if you activate the button.
Oh? Never thought thought of naming a _submit_ button..
It's just another form control, nothing special.
>I gave up on em..they look too clunky..I always use javascript instead
on custom buttons..
No need for unreliable JS. <buttonand <input type="image"exist.

Micha
Aug 26 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.