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:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['someAction']))
{
func();
}
function func()
{
echo 'pressed';
}
?>
<form method="post">
<input type="button" name="someAction" value="press me"/>
</form>
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.