...

View Full Version : Is this possible?



rossored
06-07-2004, 12:39 PM
I seem to remember reading somewhere that php allows a different action to be executed on a form if you have more than one submit button, and that the action of said form is dictated by which button the user clicks.

Presumably, I need to have the form action going to another php page where this information is digested in the form of an "IF" script, do I?

Or is it possible to write an "IF" statement on the same page that sends the user to a different page depending on which button they click?

So basically, what I want is one button to take someone to one page, and another button to take someone to another page - but both buttons are on the same form. Possible or pipe dream?

firepages
06-07-2004, 01:00 PM
you can use javascript to change the action of a form onclick , but not via PHP , all you can do with PHP is as you noted ,get the form action page to decide which button was clicked (by giving the submit buttons different names)

rossored
06-07-2004, 02:43 PM
OK thx.

Didnt really want to have to use JS but if thats the only way, then that's what I'll have to do I guess.

RR

Garadon
06-07-2004, 03:23 PM
if(isset($Submitted)&&($Submitted=='Add'||$Submitted=='Edit'||$Submitted=='Delete')
{
switch($Submitted){
case 'Add':
require('somepage1.php');
break;
case 'Edit':
require('somepage2.php');
break;
case 'Delete':
require('somepage3.php');
break;
}
/*Note if your files have a same name only with the difference the being equal to the buttons values you can skip the switcher and simply put:
require($Submitted.'something.php');*/
unset($Submitted);
}
<form method="post" action="thispage.php" >
<input type="submit" name="Submitted" Value="Add">
<input type="submit" name="Submitted" Value="Edit">
<input type="submit" name="Submitted" Value="Delete">
</form>

rossored
06-07-2004, 03:58 PM
Thanks. You had a closing parantheses missing off line 1 but thats given me something to work on. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum