6 Replies - 5555 Views - Last Post: 10 March 2009 - 07:51 PM Rate Topic: -----

#1 [email protected]  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Login and Register Form on same page

Post icon  Posted 10 March 2009 - 12:45 PM

hello,
i am trying to add my registration form to my home screen. i would like the login form on the page as well as a form for new registration.
right now, if i fill in the new registration and click 'register,' then i am taken to my failed login page because the login info was left blank.
how can i make it so that one form is omitted if another is being filled out?
i highlighted a couple of things in the code that i think might be the issue. i feel like it's something to do with the form name/id or the fact that the username and password are in both forms so maybe that's the issue... i'm stuck.

thank you!

<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>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form2">
  <table align="center">
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Username:</td>
	  <td><input type="text" name="[b]username2"[/b] 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=[b]"password2"[/b] 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">Best word to describe you is:</td>
	  <td><input value="<?php if (isset($_POST['fun_fact'])) {
echo htmlentities($_POST['fun_fact'], ENT_COMPAT, 'UTF-8');}  ?>" name="fun_fact" type="text" id="fun_fact" 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>



Is This A Good Question/Topic? 0
  • +

Replies To: Login and Register Form on same page

#2 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Login and Register Form on same page

Posted 10 March 2009 - 02:54 PM

What file does $editFormAction reference?
Was This Post Helpful? 0
  • +
  • -

#3 [email protected]  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Re: Login and Register Form on same page

Posted 10 March 2009 - 03:36 PM

it is set to $_SERVER['PHP_SELF']...

here is the code for the form action for the login and the start of the code for the new registration if that helps...

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "userprofile.php";
  $MM_redirectLoginFailed = "failLoginIndex.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_connUser, $connUser);
  
  $LoginRS__query=sprintf("SELECT username, password FROM userTable WHERE username=%s AND password=%s",
	GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $connUser) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
	 $loginStrGroup = "";
	
	//declare two session variables and assign them
	$_SESSION['MM_Username'] = $loginUsername;
	$_SESSION['MM_UserGroup'] = $loginStrGroup;		  

	if (isset($_SESSION['PrevUrl']) && false) {
	  $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
	}
	header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
	header("Location: ". $MM_redirectLoginFailed );
  }
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  ... continues to create error array, then inserts into database if no errors... but i can't get to this point because it won't let me leave the login blank


thank you!
Was This Post Helpful? 0
  • +
  • -

#4 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Login and Register Form on same page

Posted 10 March 2009 - 03:49 PM

You're going to have to figure out which Submit button was pressed, so in the script, for the section that handle log-ins, you must test the condition:

if(isset($_POST['doLogin'])) {,

which evaluates to true when the Submit button for the log-ins is pressed. As for the registration section, you must test the condition:

if(isset($_POST['register'])) {,

which should evaluate to true when the Submit button for the registration form is pressed.
Was This Post Helpful? 0
  • +
  • -

#5 [email protected]  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Re: Login and Register Form on same page

Posted 10 March 2009 - 04:42 PM

that makes sense... where would you recommend i put that code? above the doctype? where the forms are in the script below? or around the $loginFormAction and $editFormAction?

haha... or i guess none of the above if i'm wrong on all 3 counts..

thank you
Was This Post Helpful? 0
  • +
  • -

#6 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Login and Register Form on same page

Posted 10 March 2009 - 06:06 PM

I'd put the first condition around this portion of code:


if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  //...
.

So,

if(isset($_POST['doLogin'])) {
if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  //...
.
Was This Post Helpful? 0
  • +
  • -

#7 [email protected]  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Re: Login and Register Form on same page

Posted 10 March 2009 - 07:51 PM

see now i thought that made sense, but it will not work... i wrapped the code just as you have done there and put the ending curly bracket at the end of the header... and then i did the same with the if(isset($_POST['register'])) {... }.
may it will help to see the two form action files...
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}


and then the new register form is...
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}



does this help at? i'll keep trying.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1