title: Conflict between Login form and Register form in the same page
body: <p>My website has a login form present in every pages (on a top-menu) so even when a user is on the Register page the login form is still available in this top-menu.</p>
  
  <p>My problem is that in this specific case, when a user fills the register form and submits it, it returns the error that all fields are required to be filled. I found out that this is because my login form uses the same input names that my register form uses ( <code>$username</code> and <code>$password</code> ).</p>
  
  <p>So even if the register form is filled, if i leave the login form empty it will return me this error, however if i fill the login form with anything and then submit the properly filled register, there won't be any conflicts.</p>
  
  <p>Here are my <code>login form</code>, <code>register form</code>, and part of my <code>php code that process the register data</code></p>
  
  <p>login form :</p>
  
  <pre><code>&lt;form method="post" action="/ftp/index.php?login=1"&gt;
  
          &lt;div id="header_username"&gt;
              &lt;input type="text" name="username" id="txt_username" placeholder="username" required="" value="" /&gt;
          &lt;span class="username_icon"&gt;&lt;i class="fa fa-user"&gt;&lt;/i&gt;&lt;/span&gt;
          &lt;/div&gt;
          &lt;div id="header_password"&gt;
          &lt;input type="password" name="password" id="txt_password" placeholder="password" required="" /&gt;
          &lt;span class="password_icon"&gt;&lt;i class="fa fa-lock"&gt;&lt;/i&gt;&lt;/span&gt;
          &lt;/div&gt;
          &lt;div id="forgotten_pwd"&gt;
          &lt;a href=""&gt;&lt;span&gt; Forgotten Password ?&lt;/span&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div id="submit_button"&gt;
          &lt;input type="hidden" name="redirect" value="&lt;?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?&gt;" /&gt;
          &lt;button type="submit" name="submit" id="sub_login"&gt;&lt;i id="submit"class="fa fa-long-arrow-right"&gt;&lt;/i&gt;&lt;/button&gt;
          &lt;/div&gt;
          &lt;div id="button-border"&gt;&lt;/div&gt;
          &lt;div class="feedback"&gt;login successful &lt;br /&gt;redirecting...&lt;/div&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>register form :</p>
  
  <pre><code>&lt;form action="&lt;?php echo $_SERVER['PHP_SELF'].'?signup=1'; ?&gt;" method="post"&gt;
    &lt;div class="line"&gt;&lt;label for="username"&gt;&lt;?php echo lang::get("Username")?&gt; *: &lt;/label&gt;&lt;input type="text" name="username" id="username" value="&lt;?php if (isset($_POST['username'])) echo $_POST['username']?&gt;"/&gt;&lt;/div&gt;
    &lt;div class="line"&gt;&lt;label for="email"&gt;&lt;?php echo lang::get("Email")?&gt; *: &lt;/label&gt;&lt;input type="text" name="email" id="email" value="&lt;?php if (isset($_POST['email'])) echo $_POST['email']?&gt;"/&gt;&lt;/div&gt;
    &lt;div class="line"&gt;&lt;label for="password"&gt;&lt;?php echo lang::get("Password")?&gt; *: &lt;/label&gt;&lt;input type="password" name="password" id="password"/&gt;&lt;/div&gt;
    &lt;div class="line"&gt;&lt;label for="password2"&gt;&lt;?php echo lang::get("Confirm password:")?&gt; &lt;/label&gt;&lt;input type="password" name="password2" id="password2"/&gt;&lt;/div&gt;
      &lt;?php
          $rand_int1 = substr(mt_rand(),0,2);
          $rand_int2 = substr(mt_rand(),0,1);
          $rand_int3 = substr(mt_rand(),0,1);
          $captcha_answer = $rand_int1 + $rand_int2 - $rand_int3;
          $_SESSION['captcha_answer'] = $captcha_answer;
      ?&gt;              
     &lt;div class="line"&gt;&lt;label for="captcha"&gt;&lt;?php echo $rand_int1.' + '.$rand_int2.' - '.$rand_int3.' = ?';?&gt; *: &lt;/label&gt;&lt;input type="text" name="captcha" id="captcha" autocomplete="off"/&gt;&lt;/div&gt;
     &lt;div class="line submit" style="text-align:right"&gt;&lt;input type="submit" class="button" value="&lt;?php echo lang::get("Sign up")?&gt;" /&gt;&lt;/div&gt;
  &lt;/form&gt;
  
  &lt;?php endif;?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>php code that processes the data :</p>
  
  <pre><code>if (!empty($_POST)){
  
              $username = $_POST['username'];
              $email = $_POST['email'];
              $password = $_POST['password'];
              $password2 = $_POST['password2'];
              $captcha = $_POST['captcha'];
  
  
              // requiered fields &amp; validation
              if (    !isset($username)
                      || $username == ''
                      || !ctype_alnum($username)
                      || gator::getUser($username)
                      || gator::getUser($email, 'email')
                      || !isset($password)
                      || !isset($password2)
                      || !isset($_POST['captcha'])
                      || $password == ''
                      || $password != $password2
                      || filter_var($email, FILTER_VALIDATE_EMAIL) == false
                      || (int)$captcha != (int)$_SESSION['captcha_answer'])
              {
                  if ($username &amp;&amp; !ctype_alnum($username)) $_POST['username'] = '';
                  if (filter_var($email, FILTER_VALIDATE_EMAIL) == false) $_POST['email'] = '';
  
                  $errors = lang::get("All fields requiered!");
              }
  
              if ($errors == false){
  
                  $reloadaction = 'thanks';
  </code></pre>
  
  <p>My question is the following :</p>
  
  <p>Even though i know an alternative solution would be to rename the inputs of my register form for instance, is there a "cleaner" solution for this ? Is there instead anything i can add to my <code>php code that process the data</code> to make it ignore the login form's inputs when i submit the register form ? How do big websites deal with this type of conflicts ?</p>
  
  <p>Thanks a lot for trying to help me out with this !</p>
  
  <p>-Apatik</p>
  
  <p>edit : my full register code :</p>
  
  <pre><code> * Sign up init
   */
  public function initSignup() {
  
      // try to activate account?
      if (gatorconf::get('signup_use_activation') &amp;&amp; isset($_GET['activate'])){
  
          $key = $_GET['activate'];
          $user = gator::getUser($key, 'akey');
  
          if ($user){
              gator::updateUser($user['username'], array('akey' =&gt; '', 'permissions' =&gt; gatorconf::get('default_permissions_after_activation')));
              $user['permissions'] = gatorconf::get('default_permissions_after_activation');
              $this-&gt;loginUser($user);
          }
  
          header('Location: '.gatorconf::get('base_url'));
          die;
      }
  
      $errors = null;
  
      if (!empty($_POST)){
  
          $username = $_POST['username'];
          $email = $_POST['email'];
          $password = $_POST['password'];
          $password2 = $_POST['password2'];
          $captcha = $_POST['captcha'];
  
  
          // requiered fields &amp; validation
          if (    !isset($username)
                  || $username == ''
                  || !ctype_alnum($username)
                  || gator::getUser($username)
                  || gator::getUser($email, 'email')
                  || !isset($password)
                  || !isset($password2)
                  || !isset($_POST['captcha'])
                  || $password == ''
                  || $password != $password2
                  || filter_var($email, FILTER_VALIDATE_EMAIL) == false
                  || (int)$captcha != (int)$_SESSION['captcha_answer'])
          {
              if ($username &amp;&amp; !ctype_alnum($username)) $_POST['username'] = '';
              if (filter_var($email, FILTER_VALIDATE_EMAIL) == false) $_POST['email'] = '';
  
              $errors = lang::get("All fields requiered!");
          }
  
          if ($errors == false){
  
              $reloadaction = 'thanks';
  
              $activationkey = '';
  
              if (gatorconf::get('signup_use_activation')){
  
                  $activationkey = sha1(mt_rand(10000,99999).time());
                  $url = gatorconf::get('base_url').'/?signup=1&amp;activate='.$activationkey;
  
                  $subject = gatorconf::get('account_email_subject');
                  $body = gatorconf::get('account_email_text'). "\n\n" .$url;
                  $this-&gt;sendEmail($email, $subject, $body);
  
                  $reloadaction = 'goactivate';
              }
  
              // homedir will be created based on username
              $homedir = gatorconf::get('repository').'/users'.DS.$username;
  
              // if dir does not exist - try to create one
              if ($homedir != '' &amp;&amp; !is_dir($homedir)){
                  if (!mkdir($homedir, 0755, true)) {
                      echo "ERROR: User's homedir cannot be created. Check permissions. DIR = ".$homedir; die;
                  }
              }
  
              // add new user
              gator::addUser($username, array(
              'password' =&gt; $password,
              'permissions' =&gt; gatorconf::get('default_permissions_after_signup'),
              'homedir' =&gt; $homedir,
              'email' =&gt; $email,
              'akey' =&gt; $activationkey));
  
              // thanks on success or go activate!
              header('Location: '.gatorconf::get('base_url').'/?signup=1&amp;'.$reloadaction);
              die;
          }
  
      }
  
  
      if (isset($_GET['thanks'])){
  
          // thanks on success or go activate!
          header('Location: '.gatorconf::get('base_url'));
          die;
  
      }elseif (isset($_GET['goactivate'])){
  
          gator::display("header.php");
          gator::display("signup.php", array('goactivate' =&gt; 1));
  
      }else{
  
          gator::display("header.php");
          gator::display("signup.php", array('errors' =&gt; $errors));
  
      }
  
      gator::display("../../../style/include/footer.php");
  
  }
  
  
  /**
   *
  </code></pre>