The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Call a PHP function using a form/Javascript?

I have a page, index.php, with a form on it. I want to run a function, let's call it run_code() (declared in index.php)when the submit button of that form is pushed. How do I accomplish this without having to load a new page or reload the current page?

As I understand it:
"Can I run a Php function (I'm assuming any function) by clicking the submit button of a form without reloading the page?

So I'd say the image thingy doesn't cover that, though its a very handy little tool to have in one's box.

As for the I-frames solution, ok, might work, just read 'page or frame' were it says 'page' in the above posts.

But personally I don't like to hide things from the user. Say I click on a button that triggers an (hidden) server call, what happens in the mean time on my page? Nothing... Not untill the information comes back from the server. In the mean time I'm not getting any feedback at all. That's not a good model for interaction if you ask me.

And one could also argue that there's no principal difference in reloading a page or reloading a frame (be it hidden or not).

There's a reason that both sever side and client side scripting exist, they are there to do different things. I'd say, use the right tool for the right job.

Well, if you reload an image and access it using a PHP script you then have access to every PHP function within that script.

As for the hidden iframe, you only send like a maximum 10 lines of code, because you definitly want it to be instant...

In most cases, it really depends on what the situation is. I never write a page to depend on Javascript, however, if Javascript is there, I make some of the links happen without reloading the page, and then providing a pop-up alert() once the operation has completed.

There is no real set answer for this, i believe you have to make your own call on if/when you want to do something like this.

Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.

I have a page, index.php, with a form on it. I want to run a function, let's call it run_code() (declared in index.php)when the submit button of that form is pushed. How do I accomplish this without having to load a new page or reload the current page?