title: Keep text in text field after submit
body: <p>I'm building a form, and I want that all the inserted values will be kept, in case of form submit failure. This is my code:</p>
  
  <pre><code>&lt;?php
  $error = "";
  $name = "";
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
     $name = $_POST["name"];
  
     // Verify $_POST['name'] greater than 4 chars
     if ( strlen($name) &lt; 4 ){
          $error= 'Name too short!';
      }
  }
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="post" action="&lt;?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?&gt;" name="myForm" id="idForm"&gt;
         &lt;input type="text" placeholder="Name" id="name" name="name" value=""/&gt;
         &lt;input type="submit" value="submit"/&gt;
      &lt;/form&gt;
          &lt;?php 
              echo "&lt;h2&gt;Input:&lt;/h2&gt;"; 
              echo $name;
              if($error) {
                  // No Update AND refresh page with $name in text field
                  echo "&lt;br/&gt;" . $error; 
              } else {
                  // Update name in DB
              }
         ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I would like that name field keeps the inserted input text, after submit. I tried to do with php code in input value but doesn't work. Any ideas?</p>