This particular example is coded in PHP, which is a server-side language so you won't be able to take code from it to recreate it.
My favourite way to approach this task would be to use a PHP comboform. That is, a PHP script that can render one or more different pages, depending on whether or not the user has submitted a form or not. A simple example of this is below.
As for how the developer managed to make the text on the dog tags change based upon the input; you'll notice that they're dynamically generated images. There are a few PHP modules that are capable of that, but the best (and the one that was probably used here) is GD2. You'd have to do some reading on the GD2 API to figure out how to use it properly.
PHP Code:
<html>
<head>
<title>PHP Comboform example</title>
</head>
<body>
<?php
if (count($_POST) > 0) {
// if the $_POST array contains data then the form must have been submitted already.
echo 'Hi '. $_POST['name'] .', you have already clicked the submit button.';
} else {
// otherwise we render the form.
echo '<form name="comboform" method="post" action="'. $_SERVER['PHP_SELF'] .'">\n';
echo ' <input type="text" name="name" />\n';
echo ' <input type="submit" name="submit" />\n';
echo '</form>';
}
?>
</body>
</html>
Disclaimer: I haven't tested this so you might need to correct a few silly errors to make it work. Additionally, $_SERVER['PHP_SELF'] is one of the more exploitable parts of PHP and this script has no defense whatsoever against cross-site scripting, so make sure you do your homework on PHP security.