At the moment my code is something like this: <form action="" method="post"> Form Stuff </form> <?php function name() { echo "Stuff" } PHP: OK, so I want it so when I submit the form, it executes name(). What should I specify for form action? I tried ?action=name, but I feel I am missing something here, thanks, BP
This is a common mistake. You can not mix PHP with Javascript like this. PHP is on your server, while javascript is on the client's browser. You will have to submit the form to the server so PHP can validate it (or to execute PHP functions in general). Either you do that, or you ask in the javascript section if whatever you're trying to do can be accomplished with javascript, and not PHP. (Note that is you want to validate the form, you HAVE to use PHP because javascipt is not secure)
I'm not using any Javascript, but I understand where you are coming from. So how do I execute functions like on any CMS software by using ?functionname? For example the sNews CMS function goes: index.php?login for the login page and vBulletin uses showthread.php?t=threadID. So how can I use it like that, would it involve .htaccess? I want to keep the amount of files in my script as minimal as possible, BP
Sorry, I misunderstood your question. The action attribute tells the browser where to send the data to. (file name or URL of the page). To execute the function when the form is sent, do something like: if (isset($_POST)) { name(); } PHP:
Sorry for double posting. This does work, but I also want to be able to recognise wat for its being posted from. Say I have three forms in different files, and each one has a different result when I submit it. I tried giving the form a name and the using ['formname'] after isset($_POST) Cheers, BP
Add a hidden field to the forms: <input type="hidden" name="formname" value="My form 1" /> HTML: And in your script receive the value with: $form_name = $_POST['formname']; PHP: