开发者

How to create a button and its event handler in PHP?

I开发者_JS百科 am new to PHP but I need to create a button on a simple page and have its event handler. Any clue?


In the OnClick event of the button, insert JavaScript code that points to the PHP script which you want to run when the button is clicked.

<input type="button" value="Say Hi!" onclick="location='test.php'" />


PHP doesn't work like .Net. So what you are talking about it actually not directly possible.

What you will need to do is create the raw markup for your form. At minimum a form tag and your button. Set the form's action to a php script on your server, such as "button_action.php" and have it accept, via GET or POST, whatever data you wanted to send. (or if you are just talking about enacting some action, you don't need to check anything)

Again, this isn't .Net, so there is no postback, and you will not come back to the page. If you want to do that, you will have to redirect back from your other script.


Ahmad Farid, how say Geoffrey Van Wyk, you can use the event "onclick" of an input element (button, for example).

Maybe AJAX is your solution (not reload all page). A simple example of 'click' and run a script (maybe CGI, or PHP) it's here: http://www.degraeve.com/reference/simple-ajax-example.php

Easy & useful :)

PD: Sorry for my english ;(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜