title: Smarty form validation using PHP
body: <p>I want to validate my form using PHP on Smarty template. I have searched in the web and here for some solutions, but nothing work in my case. I want to stay on the same page if some field is empty or filled with incorrect data. The file "result.php" is the page where the correct submited data goes to. I have done it, using <strong>javascript</strong>, but i want to know how to do it with <strong>PHP</strong> in case of disabled javascript in the user browser and for more complex check run (white spaces, empty fields, incorrect characters...). The posted PHP script does not do any validation and i get an undefined index: error. I post a piece of my code. Please, help. Thanks in advance!</p>
  
  <p><strong>php code (index.php):</strong></p>
  
  <pre><code>if (!empty($_POST)) {
  if (!empty($scrubbed['name']) || !empty($scrubbed['age'])) {
      header("Location: result.php");
   }
  else {
      $smarty-&gt;assign('error', 'Please fill out the form completely');
      $smarty-&gt;display('index.tpl');
   }
  }
  </code></pre>
  
  <p><strong>smarty code (index.tpl):</strong></p>
  
  <pre><code>{$error}
  &lt;table width="600" align="center" cellpadding="5"&gt;
  &lt;form name="infoform" action="result.php" method="post"&gt;  
  &lt;tr&gt;
      &lt;td&gt;&lt;div align="right"&gt;Name:&lt;/div&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="name" size="20"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;div align="right"&gt;Age:&lt;/div&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input type="number" name="age" size="2" min="1" max="65"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
  ...  
  </code></pre>