executing a php function from either html or java script

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
kinga
Forum Newbie
Posts: 1
Joined: Tue Oct 09, 2007 9:01 pm

executing a php function from either html or java script

Post by kinga »

Hey guys,

i am trying to make a button that will execute a php function that i have in the same page.
Can some please give me an example of how to do this?

Thanks,
Kinga
lettie_dude
Forum Commoner
Posts: 65
Joined: Thu Dec 07, 2006 10:10 am

Post by lettie_dude »

Place the following in the form tag:

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
This will submit the page to itself.

Then add your function code to the top of the page.

Wrap this in something like:

Code: Select all

if(isset($_POST['submit'])) {

// Your code

}
Then the code will only process when the submit button or whatever you call it is actioned.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Never ever ever ever ever ever ever use PHP_SELF.

We've talked about it enough that searching should tell you why.
Post Reply