If I have a form that utilises several buttons which each require a slightly different process to be followed on submission, how do I tell them apart?
Example:
<button type='submit' name='add'>
<button type='submit' name='remove'>
is it a simple case of $_POST['add'] being '1' or TRUE, and the other one being false?
Cheers,
HKHorus,
yeah...each button would have it's own $_POST["name"] set....altho using multiple submit buttons on one form is not recommended.
if(!$_POST["add"] & !$_POST["remove"])
{
exit;
}
elseif($_POST["remove"] & !$_POST["add"])
{
//remove
}
elseif($_POST["add"] & !$_POST["remove"])
{
//add
}
that's just an example....that should work provided both buttons don't submit.If I remember correctly Goldilocks had a similar form and had a post in client side scripting about disabling the second buttom.but yeah...the button will create its own $_POST["name"] = 'value';
(ps: excuse any code errors,I'm in a bit of a rush)again, thanks Willamoose.
It's nice to know that I am thinking on the right lines anyway
maybe I can become a PHP guru? somehow, in the far-flung future?????
Cheers,
HKd'oh:
just gave this a try:
<?php
if (isset($_POST['btn1']))
{
echo $_POST['btn1'];
echo "<br>";
echo $_POST['btn2'];
}
?>
<form action='test.php' method='post'>
<button type='submit' name='btn1'>Button 1</button>
<button type='submit' name='btn2'>Button 2</button>
</form>
And it prints both button values out!
Guess its a client side thing instead.Originally posted by Horus_Kol
again, thanks Willamoose.
It's nice to know that I am thinking on the right lines anyway
maybe I can become a PHP guru? somehow, in the far-flung future?????
Cheers,
HK
2 answers in a row glad to help.
hehe....it's possible ,I've taken to teaching anyone who wants me to(one of my best friends,his gf,possibly Arwen or EightOfHearts from 0é®檇evelopment group]) so it's not exactly a steep curve.hehe..now you've got a new years resolution
echo 'become a php guru';
saga continues over the other channel (<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=30673">http://www.htmlforums.com/showthread.ph ... adid=30673</a><!-- m -->)
Cheers for your input though Moose,
HK<button type='submit' name='btn1'>Button 1</button>
<button type='submit' name='btn2'>Button 2</button>
why are you using buttons? they don't work with forms, they are a javascript onclick button.never knew that - but they do work.
my source of html advice and tag info recommends the BUTTON over an INPUT of type button, so I went with that.
and I fixed my problem so i have no problem now.
(see the client side link)
Example:
<button type='submit' name='add'>
<button type='submit' name='remove'>
is it a simple case of $_POST['add'] being '1' or TRUE, and the other one being false?
Cheers,
HKHorus,
yeah...each button would have it's own $_POST["name"] set....altho using multiple submit buttons on one form is not recommended.
if(!$_POST["add"] & !$_POST["remove"])
{
exit;
}
elseif($_POST["remove"] & !$_POST["add"])
{
//remove
}
elseif($_POST["add"] & !$_POST["remove"])
{
//add
}
that's just an example....that should work provided both buttons don't submit.If I remember correctly Goldilocks had a similar form and had a post in client side scripting about disabling the second buttom.but yeah...the button will create its own $_POST["name"] = 'value';
(ps: excuse any code errors,I'm in a bit of a rush)again, thanks Willamoose.
It's nice to know that I am thinking on the right lines anyway
maybe I can become a PHP guru? somehow, in the far-flung future?????
Cheers,
HKd'oh:
just gave this a try:
<?php
if (isset($_POST['btn1']))
{
echo $_POST['btn1'];
echo "<br>";
echo $_POST['btn2'];
}
?>
<form action='test.php' method='post'>
<button type='submit' name='btn1'>Button 1</button>
<button type='submit' name='btn2'>Button 2</button>
</form>
And it prints both button values out!
Guess its a client side thing instead.Originally posted by Horus_Kol
again, thanks Willamoose.
It's nice to know that I am thinking on the right lines anyway
maybe I can become a PHP guru? somehow, in the far-flung future?????
Cheers,
HK
2 answers in a row glad to help.
hehe....it's possible ,I've taken to teaching anyone who wants me to(one of my best friends,his gf,possibly Arwen or EightOfHearts from 0é®檇evelopment group]) so it's not exactly a steep curve.hehe..now you've got a new years resolution
echo 'become a php guru';
saga continues over the other channel (<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=30673">http://www.htmlforums.com/showthread.ph ... adid=30673</a><!-- m -->)
Cheers for your input though Moose,
HK<button type='submit' name='btn1'>Button 1</button>
<button type='submit' name='btn2'>Button 2</button>
why are you using buttons? they don't work with forms, they are a javascript onclick button.never knew that - but they do work.
my source of html advice and tag info recommends the BUTTON over an INPUT of type button, so I went with that.
and I fixed my problem so i have no problem now.
(see the client side link)