Simple PHP Form Templating
<p>You have a PHP form with the following field in it:</p>

<p>(code block 1) </p>

<pre><code>City: &lt;input type="text" name="city"&gt;&lt;br&gt;
</code></pre>

<p>The form's <code>action attribute</code> is set to <code>itself</code>. When <code>submitted</code> to the server, the page validates the field, and if it's invalid it returns the same page with:</p>

<ol>
<li>An error message</li>
<li>A red border around the form text input box</li>
<li>The value the user originally inputted inside the form input text box</li>
</ol>

<p>I could use an <code>if then else</code> construct and return <code>code block 2</code> if invalid.</p>

<p>(code block 2)</p>

<pre><code>&lt;?php echo "The form field with red border has an invalid entry"; ?&gt;
City: &lt;input type="text" name="city"
style="border-color:red" value="&lt;?php echo $record-&gt;city ?&gt;"&gt;&lt;br&gt;
</code></pre>

<p>My question is, if you were to add some templating to <code>code block 1</code> so that you wouldn't need <code>code block 2</code>, how would you do it?</p>

<p>Please narrow your <em>answer set</em> to:</p>

<ol>
<li>pure PHP answers (without any external templating  libraries or PHP frameworks).</li>
<li>suitable for someone for whom PHP is the only server side scripting they know (and they are relatively inexperienced with it).</li>
</ol>