-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
55 lines (47 loc) · 1.25 KB
/
demo.php
File metadata and controls
55 lines (47 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// demo.php
require 'htmx_class.php';
if (HTMX::isRequest()) {
// Example: if a specific button triggered the request
$trigger = HTMX::getTrigger();
if ($trigger === 'loadMessageButton') {
HTMX::pushUrl('/message');
HTMX::trigger('messageLoaded', ['status' => 'ok']);
echo "<div class='message'>Hello from HTMX response!</div>";
exit;
}
if ($trigger === 'refreshSection') {
HTMX::refresh();
exit;
}
// Default HTMX response
echo "<p>HTMX request received. Trigger: " . htmlspecialchars($trigger) . "</p>";
exit;
}
// Non-HTMX: render full page
?>
<!DOCTYPE html>
<html>
<head>
<title>HTMX PHP Demo</title>
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
</head>
<body>
<h1>HTMX PHP Integration Demo</h1>
<button id="loadMessageButton"
hx-post="demo.php"
hx-trigger="click"
hx-target="#response"
hx-vals='{}'>
Load Message
</button>
<button id="refreshSection"
hx-post="demo.php"
hx-trigger="click"
hx-target="#response"
hx-vals='{}'>
Refresh Page
</button>
<div id="response" style="margin-top:20px;"></div>
</body>
</html>