PHP function as form action: possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
~fleece~
Forum Newbie
Posts: 12
Joined: Sun Apr 04, 2004 10:18 pm

PHP function as form action: possible?

Post by ~fleece~ »

Is it possible to do something like:

<form action="some php function" method="post">

and if not how can I make a form call a PHP function in some other way?

Thanks :)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You can't (like that) as PHP is server side so you'de have to send another request to the server. So you could do something like <form action="foo.php?func=somefunc" action="post">

Then in foo.php ...
if(!empty($_GET['func']) && function_exists($_GET['func'])){
$_GET['func']();
}

or put the func in a hidden form field and use $_POST['func'] but be sure to check for functions you only want to allow, i.e don't allow exec() etc..
Post Reply