PAD - PHP Application Driver


home | manual | reference | regression | sequence | develop | apps


Todo

PHP
todo.php
HTML
todo.pad
Result
<?php

$title
= 'Todo List';
$dataFile = DAT . 'demo/todos.json';
$message = '';

$todos = [];

if (
file_exists ( $dataFile ) ) {
$json = file_get_contents ( $dataFile );
$todos = json_decode ( $json, TRUE ) ?: [];
}

$hasTodos = count ( $todos ) > 0;
$doneCount = count ( array_filter ( $todos, fn($t) => $t ['done'] ) );
$pendingCount = count ( $todos ) - $doneCount;

?>
<p>Manage your tasks with this simple todo list.</p>

{if $message}
<div class="message">{$message}</div>
{/if}

<h2>Add New Task</h2>

{todo 'add', 'Add Task'}
<input type="text" name="task" placeholder="Enter a new task..." required style="flex: 1;">
{/todo}

<h2>Tasks ({$pendingCount} pending, {$doneCount} done)</h2>

{todos}

<table>

<tr>
<th>Task</th>
<th style="width: 120px;">Added</th>
<th style="width: 5%; text-align: center;" colspan="2">Actions</th>
</tr>

@start@

<tr{if $done} class="todo-item done"{/if}>
<td>{$task}</td>
<td style="font-size: 12px; color: #999;">{$date | substr (0, 10)}</td>
<td>
{if ! $done}
{todo 'done', 'Done'}
<input type="hidden" name="id" value="{$id}">
{/todo}
{/if}
</td>
<td>
{todo 'delete', 'Delete'}
<input type="hidden" name="id" value="{$id}">
{/todo}
</td>
</tr>

@end@

</table>

{if $doneCount > 0}
{todo 'clear', 'Clear Completed Tasks'}{/todo}
{/if}

@else@

<p>No tasks yet. Add one above!</p>

{/todos}

Manage your tasks with this simple todo list.

Add New Task

Tasks (0 pending, 0 done)

No tasks yet. Add one above!




home | manual | reference | regression | sequence | develop | apps

(c) 2003-2025 Herbert Groot Jebbink