title: How should I split my php files so that html forms don't break my code?
body: <p>In my current website project I have chunks of php and html code that are repeated throughout the project. For example, every page has the same header and footer as all the others. So, for the sake of modularizing my code I have created separate php files for things like these. Here is an example of my header.php file.</p>
  
  <pre><code>//header.php
  &lt;?php
  
      if(isset($_POST['submittext'])) {
          echo $_POST['sometext'];
      }
  
  ?&gt;
  &lt;div id="header"&gt;
      &lt;form action="header.php" method="post"&gt;
          &lt;input type="text" name="sometext"&gt;
          &lt;input type="submit" name="submittext"&gt;
      &lt;/form&gt;
  
      &lt;div id="somediv"&gt;
          &lt;?php
              //Some more php
          ?&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And here is an example of a file that contains code for things unique to the page, unlike the header or footer. Call this file home.php.</p>
  
  <pre><code>//home.php
  &lt;?php
      //Some php 
  ?&gt;
  
  &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;!-- Style sheets, etc. --&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;?php include('header.php'); ?&gt; //Here I include the above file
  
          &lt;div id="main"&gt;
              &lt;!-- Html for everything below the header --&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now the problem is that I have a form in the header.php file. So when I submit the form, the action attribute says to reload header.php. But if it does that, then the other code in home.php doesn't load such as the "main" div. So my question is, how can I modularize my code to prevent very long and hard to read php files, while also being able to load all my content? My first idea was to just put <code>header('Location: home.php');</code> after I process the form in the header.php file, but then if I include the header.php file in another page, say home2.php, it will redirect me back to home.php rather than home2.php.</p>