Re: Directing form to different handlers?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It would be much simpler and cleaner to use Javascript to modify the form's
action attribute onClick.

On Mon, Jun 1, 2009 at 2:28 PM, Shawn McKenzie <nospam@xxxxxxxxxxxxx> wrote:

> Jason Pruim wrote:
> >
> > On May 31, 2009, at 10:53 PM, Angus Mann wrote:
> >
> >> Hi all. I realize this is more an HTML question than PHP but I'm sure
> >> someone here can help.
> >>
> >> I have several forms with lots (dozens) of text inputs. If the user
> >> presses the "Update" button I want the form handled by "update.php"
> >> but if they press "Delete" it needs to be handled by "delete.php" or
> >> "add.php" and so-on depending on the button they press.
> >>
> >> But when establishing the form I can only have <form method="POST"
> >> action="delete.php"> or "add.php" or whatever.
> >>
> >> Is there a way to direct the content of the form do a different
> >> handler depending on the button?
> >>
> >> I know I can use javascript to direct to a constructed URL and append
> >> ?name=smith&address=hishouse&telephone=28376.....and so on but this is
> >> not practical when there are dozens of entries....the URL becomes
> >> massive. I prefer to use "POST" and then use PHP to extract the POST
> >> array.
> >>
> >
> > Couldn't you use a switch statement in a process.php file?
> >
> > <?PHP
> >
> > $var = $_GET['switchvar'];
> >
> > switch($var) {
> >
> >     case "add";
> >     include("add.php");
> >     break;
> >
> >     case "delete";
> >     include("delete.php");
> >     break;
> >
> >     default;
> >     echo "Nothing selected";
> >     break;
> >
> > }
>
> Yes, something like this except it would be $_POST.  Your form/buttons
> would be something like:
>
> <form method="POST" action="process.php">
> ..........
> <input type="submit" name="submit" value="add">
> <input type="submit" name="submit" value="update">
> <input type="submit" name="submit" value="delete">
> </form>
>
>
> And then process.php with a switch or something using the value of
> $_POST['submit'].
>
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux