javascript – Executing php on button press


I would like to create a button, which will execute the php code when pressed. The issue here is the construction like this does not work:

    if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['someAction']))
    function func()
        echo 'pressed';   

<form method="post">
    <input type="button" name="someAction" value="press me"/>

It gives an error: “Expected tag name. Got ‘?’ instead”

Not surprisingly, a solution like this does not work either:

<div class="mydiv"><?php do_shortcode("[shortcode_name]");?></div>

However, the idea of using the shortcode is actually fine, but it has to run the shortcode only when the button is pressed.

I have also tried using JavaScript for the button, which worked, but I don’t know an easy way to run the php code from JavaScript.

If you have any idea on how to do this, your answers will be welcome.

Just for context, I am using elementor for this, the html block to be exact.

user9102437 11 months 2021-09-05T13:39:05-05:00 0 Answers 0 views 0

Leave an answer