Re: Using Switch to control <form action . . >

From: Date: Sat, 16 Mar 2002 00:41:40 +0000
Subject: Re: Using Switch to control <form action . . >
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-88720@lists.php.net to get a copy of this message
On Fri, 15 Mar 2002, Andre Dubuc wrote: > I'd like to control which php file is called when clicking two buttons on the > bottom of a form; one called "Add Names", the other "Submit" > > I've tried the following with no success: > > ******************************************* > <form action= > switch ($name) { > case add: > "rap.php" method "get">; > break; > case submit: > "rap2.php" method "get">; > break; > } > > . . . > > <input type="submit" name="add" value="Add Names"> > <input type="submit" name="submit" value="Submit"> > </form> > > ************** > > I'm still a newbie, and this is the first time I've tried to use a switch > statement. I've probably performed an illegal operation by splitting the > <form action . .> statement. Yup, you're not switching between HTML and PHP properly. Whenever you switch between literal HTML code (which is processed by the browser at the end of the transmission) and PHP code (which is processed by the server before the transmission), you need to indicate this to the server. Try this: <form action="<? switch ($name) { case add: ?>rap.php<? break; case submit: ?>rap2.php<? break; } ?>" method="get"><input type="submit" name="add" value="Add Names"> <input type="submit" name="submit" value="Submit"> </form> Notice that all the PHP code is enclosed between <? and ?>. I switched back and forth liberally (normally, for the sake of readability, I'd probably do "print 'rap.php;'" instead of "?>rap.php<?") so you could see how it's possible to switch more or less at any moment. miguel

« previous php.general (#88720) next »