Debt Consolidation - Problem Mortgage - Books - Credit Cards - Bad Credit Mortgages

PDA

View Full Version : Some PHP function help


blueparukia
Oct 29th 2007, 4:24 am
At the moment my code is something like this:

<form action="" method="post">
Form Stuff
</form>

<?php
function name()
{
echo "Stuff"
}

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

nico_swd
Oct 29th 2007, 4:41 am
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)

blueparukia
Oct 29th 2007, 5:33 am
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

nico_swd
Oct 29th 2007, 5:37 am
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();
}

blueparukia
Oct 29th 2007, 5:54 am
Thank you :D Rep will be given,

Cheers,

BP

blueparukia
Oct 30th 2007, 2:23 am
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

nico_swd
Oct 30th 2007, 2:29 am
Add a hidden field to the forms:

<input type="hidden" name="formname" value="My form 1" />


And in your script receive the value with:

$form_name = $_POST['formname'];

blueparukia
Oct 30th 2007, 2:31 am
Thank you :)

BP