Page 1 of 1

Login User and Registration Form on Same Page

Posted: Tue Mar 10, 2009 5:06 pm
by ninethousandfeet
first, i'd like to start off by saying hello to everyone... i am 100% new to this website and i will try my best to keep my posts to a minimum so others can take advantage of the great advice people have to offer.

my current problem is in regards to my home page. i want my home page to have 'Login User' with username and password fields for those already registered, but also a 'New Registration' form for those who have yet to join my website. the best real life example i can give is Facebook's home page.

the issue i'm running into is that i am having trouble separating the two; login and new registration. a new user fills in the fields of the new registration form and it will not insert the data because the login info is left blank. obviously this is a problem, because they cannot fill in the login info as they have yet to sign up. i'm posting the code of the two forms, if someone needs to see something above the <doctype> by all mean let me know and i'll post it as well.

again, thank you for having me to the forum... i look forward to a great experience.

Code: Select all

 
<fieldset>
  <legend>Login</legend>
  <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
    <p>
      <label for="username">Username</label>
      <input name="username" type="text" id="username" size="22" />
      <label for="password">Password</label>
      <input name="password" type="password" id="password" size="22" />
    </p>
    <a href="forgotUserPassword.php">Forgot password and/or username?</a>
    <p>
      <label for="doLogin"></label>
      <input type="submit" name="doLogin" id="doLogin" value="Login" />
    </p>
  </form>
</fieldset>
<fieldset>
  <legend>Sign Up!</legend>
  <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form2">
    <table align="left">
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Username:</td>
        <td><input type="text" name="username2" value="<?php if (isset($_POST['username'])) {
echo htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8');}  ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Password:</td>
        <td><input type="password" name="password2" value="" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Confirm Password:</td>
        <td><input name="confirm_password" type="password" id="confirm_password" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Email:</td>
        <td><input type="text" name="email" value="<?php if (isset($_POST['email'])) {
echo htmlentities($_POST['email'], ENT_COMPAT, 'UTF-8');}  ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Confirm Email:</td>
        <td><input value="<?php if (isset($_POST['confirm_email'])) {
echo htmlentities($_POST['confirm_email'], ENT_COMPAT, 'UTF-8');}  ?>" name="confirm_email" type="text" id="confirm_email" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">&nbsp;</td>
        <td><input name="register" type="submit" id="Register" value="Register" />
          <input type="reset" name="clear" id="clear" value="Clear" /></td>
      </tr>
    </table>
    <input type="hidden" name="user_id" value="" />
    <input type="hidden" name="register_date" value="NOW()" />
    <input type="hidden" name="MM_insert" value="form1" />
  </form>
</fieldset>
 

Re: Login User and Registration Form on Same Page

Posted: Thu Mar 12, 2009 5:06 am
by susrisha
Since you have two forms, i would ask you to write separate action pages for each form. Else there is always an option of submit button value to know which information is submitted. That way you can have the same action but different for each of the forms.

Re: Login User and Registration Form on Same Page

Posted: Thu Mar 12, 2009 5:11 am
by The_Anomaly
Yeah, I do this by setting two different form actions. Maybe with a querystring or something specifying whether it's a registration or login.