Normalize a form value and build a short status.

form-summary Form data should be normalized before a handler decides what to do next. This example keeps the form value local and scalar for replay.

Form Summaries

name
form_summary.php
Replay: real traced execution (multi-file project)
<?php
$name = " Ada ";
$trimmed = trim($name);
$status = $trimmed === "" ? "missing" : "ready";
$summary = $status === "ready" ? "hello " . $trimmed : "name missing";

echo "status=" . $status . "\n";
echo "summary=" . $summary . "\n";
<?php
$name = " Lin ";
$trimmed = trim($name);
$status = $trimmed === "" ? "missing" : "ready";
$summary = $status === "ready" ? "hello " . $trimmed : "name missing";

echo "status=" . $status . "\n";
echo "summary=" . $summary . "\n";
<?php
$name = " ";
$trimmed = trim($name);
$status = $trimmed === "" ? "missing" : "ready";
$summary = $status === "ready" ? "hello " . $trimmed : "name missing";

echo "status=" . $status . "\n";
echo "summary=" . $summary . "\n";
  1. $name ← Ada , $trimmed ← Ada, $status ← ready, $summary ← hello Ada

    1<?php2$name→  Ada  = " Ada "; //@name=" Lin ", " "3$trimmed→ Ada = trim($name Ada );4$status→ ready = $trimmedAda === "" ? "missing" : "ready";5$summary→ hello Ada = $statusready === "ready" ? "hello " . $trimmed : "name missing";67echo "status=" . $statusready . "\n";8echo "summary=" . $summaryhello Ada . "\n";
    outputstatus=ready
    summary=hello Ada
  1. $name ← Lin , $trimmed ← Lin, $status ← ready, $summary ← hello Lin

    1<?php2$name→  Lin  = " Lin ";3$trimmed→ Lin = trim($name Lin );4$status→ ready = $trimmedLin === "" ? "missing" : "ready";5$summary→ hello Lin = $statusready === "ready" ? "hello " . $trimmed : "name missing";67echo "status=" . $statusready . "\n";8echo "summary=" . $summaryhello Lin . "\n";
    outputstatus=ready
    summary=hello Lin
  1. $name ← , $trimmed ← (empty), $status ← missing, $summary ← name missing

    1<?php2$name = " ";3$trimmed→ (empty) = trim($name );4$status→ missing = $trimmed(empty) === "" ? "missing" : "ready";5$summary→ name missing = $statusmissing === "ready" ? "hello " . $trimmed : "name missing";67echo "status=" . $statusmissing . "\n";8echo "summary=" . $summaryname missing . "\n";
    outputstatus=missing
    summary=name missing