Home php Handling button clicks

Handling button clicks




How to handle the event of clicking on a button? As I understand it, there is no such thing:

private void button1_Click (object sender, EventArgs e)

How to make certain php code work exactly when you click on the desired button?

Answer 1, authority 100%

The most important thing is to understand that your button is with the user , and your handler is on the server . And the button can be drawn in one file, and processed in another. All this is separately .

First option, the button can be presented as others wrote:

& lt; form action = "/ script / which / will / process / this_form.php" method = "POST" & gt;
   & lt; input name = "myActionName" type = "submit" value = "Execute" / & gt;
& lt; / form & gt;

Handler code:

& lt;? php
  if (isset ($ _ POST ['myActionName'])
    // do whatever
? & gt;

Or other solution. In the age of AJAX, you can do it like this:

& lt; button id = "myActionButton" & gt; Execute & lt; / button & gt;
& lt; script & gt;
  $ ('# myActionButton'). click (function () {
    $ .post (
      {myActionName: "Run"}
& lt; / script & gt;

But for this you also need to include the jQuery library.

Answer 2, authority 8%

& lt; form action = "here_your.php" & gt;
& lt; input type = 'button' value = "KNOPKA" & gt;
& lt; / form & gt;

Answer 3

Give the button a name (write the name attribute) and put it below instead of an ellipsis.
when clicked, the test.php file will be triggered

if (isset ($ _ POST ["....."])) {
require "test.php";}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions