0

Say I have a page login.php with the fields username and password. It also of course has a button to submit. How do I get it so that, if the user enters his/her name and password and hits submit, IF the user is not yet verified it returns to login.php but in addition to the username and password fields there is an activation field as well?? Sample code would be much appreciated. Thanks in advance.

lostInTransit
  • 70,519
  • 61
  • 198
  • 274
pintee
  • 119
  • 1
  • 10

2 Answers2

0

Try redirecting to login.php?validation=true, then in PHP chceck by $_GET['validation'] for the parameter to be true. If it's not, the parameter is not provided (you are propably in login.php), or it's not true.

If you don't want to have any parameters send a form (with action to login.php) with different name than the one you use for logging in, and then check in the beginning of your login.php if the form was submitted. (In such case it's just submitting data by POST, not GET)

Lemur
  • 2,659
  • 4
  • 26
  • 41
  • Thanks pablo. What do you mean by 'with different name than the one you use for logging in'? – pintee Apr 19 '13 at 08:09
  • I meant a hidden field there ``, but this way is pretty messy. You may try to send `POST` data directly (http://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php), but I think the easiest way will be doing it with `GET` - you just need to redirect to `login.php?validation=true&username=someuser` and check on the beginning if the value is set (`if ($_GET['validation'] == "true") { show the field }`). You may also `&username=someuser` to re-enter the username field, because after any redirect your form will be cleared – Lemur Apr 19 '13 at 08:27
0

I came up something like below, it is not tested, but it should show the idea:

<?php
$showActivate = false;
if ( !empty($_POST) ) {

   // perform your username and password validation here
   // and set $userValid value
   ...

   if ( !$userValid ) {
      $showActivate = false;
   }

}
?>
<form action="login.php" method="POST">
 <input name="username"/>
 <input name="password"/
 <?php if ( $showActivate ):?>
  <input name="activation"/>
 <?php endif; ?>
</form>
XuDing
  • 1,982
  • 18
  • 27