I would like to know how to call a php code in a button that triggers an iframe, and that code should be opened in the iframe.
I would like to know how to call a php code in a button that triggers an iframe, and that code should be opened in the iframe.
To call a PHP code after clicking this button, use an AJAX request for the desired PHP file.
If the code should be executed in the iframe, then use src
for the PHP file or integrate it with the page you need. If you need to pass a variable through the URL, just do it by src
and capture the information by $_GET
in PHP.
You can enable the iframe and set the src of it dynamically as in this jsfiddle that I just did: link
Well, without much ado:
<?php
if (!empty($_GET['act'])) {
echo "Olá, Stack Overflow!"; //Seu código vai aqui, enfim...
} else {
?>
(.. html ..)
<form action="index.php" method="get">
<input type="hidden" name="act" value="run">
<input type="submit" value="Clique aqui!">
</form>
<?php
}
?>