|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +require __DIR__ . '/../src/tracy.php'; |
| 4 | + |
| 5 | +use Tracy\Debugger; |
| 6 | + |
| 7 | +// For security reasons, Tracy is visible only on localhost. |
| 8 | +// You may force Tracy to run in development mode by passing the Debugger::Development instead of Debugger::Detect. |
| 9 | +Debugger::enable(Debugger::Detect, __DIR__ . '/log'); |
| 10 | + |
| 11 | + |
| 12 | +// Form posted into a hidden iframe – Tracy starts a new bar instance inside |
| 13 | +// the iframe, so the request is effectively invisible (issue nette/tracy#427). |
| 14 | +if (!empty($_POST['data'])) { |
| 15 | + bdump($_POST['data'], 'received in hidden iframe'); |
| 16 | + echo '<script>parent.setStatus(' . json_encode($_POST['data']) . ' + " received!")</script>'; |
| 17 | + exit; |
| 18 | +} |
| 19 | + |
| 20 | +?> |
| 21 | +<!DOCTYPE html><html class=arrow><link rel="stylesheet" href="assets/style.css"> |
| 22 | + |
| 23 | +<h1>Tracy: hidden iframe form demo (issue #427)</h1> |
| 24 | + |
| 25 | +<p>Submitting the form posts into a hidden iframe. The request <em>is</em> handled |
| 26 | + by Tracy, but the bar is rendered inside the invisible iframe, so it is not |
| 27 | + shown in the parent page.</p> |
| 28 | + |
| 29 | +<iframe name="hiddenIframe"></iframe> |
| 30 | + |
| 31 | +<form target="hiddenIframe" action="iframe-form.php" method="post"> |
| 32 | + <input type="text" name="data" value="hello"> |
| 33 | + <input type="submit"> |
| 34 | +</form> |
| 35 | + |
| 36 | +<h2 id="status">Waiting for submit...</h2> |
| 37 | + |
| 38 | +<script> |
| 39 | + function setStatus(text) { |
| 40 | + document.getElementById('status').innerText = text; |
| 41 | + } |
| 42 | +</script> |
| 43 | + |
| 44 | +<?php |
| 45 | +if (Debugger::$productionMode) { |
| 46 | + echo '<p><b>For security reasons, Tracy is visible only on localhost. Look into the source code to see how to enable Tracy.</b></p>'; |
| 47 | +} |
0 commit comments