By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

how to create Re-enter password / Username ?

George Lft
P: 26
In my new registration page, i'm trying to create a double entry password / username to validate their entry . haven't decided which one, probably i'll go just with the password . What is the PHP codes is like ?. - to validate the two password fields that it's same ? before it sent....Thanks.
Dec 30 '07 #1
Share this Question
Share on Google+
10 Replies


Markus
Expert 5K+
P: 6,050
In my new registration page, i'm trying to create a double entry password / username to validate their entry . haven't decided which one, probably i'll go just with the password . What is the PHP codes is like ?. - to validate the two password fields that it's same ? before it sent....Thanks.
Javascript or of course Ajax but that's probably a little more complicated for what you want.
First you'd want to grab the names of the input - maybe pass them through the parenthesis of your 'submit' button, which should have an onclick attribute(the submit button) to fire the javascript function. You'd then compare the value of those two inputs (document.form_name.input_name.value == etc.) If they match you've got a winner, if not return false and alert them that they must re-do the passwords.

Don't have time to write you a pseudo code atm, on my way out.

Hope this helps.

Markus.
Dec 30 '07 #2

George Lft
P: 26
In my new registration page, i'm trying to create a double entry password / username to validate their entry . haven't decided which one, probably i'll go just with the password . What is the PHP codes is like ?. - to validate the two password fields that it's same ? before it sent....Thanks.
Javascript or of course Ajax but that's probably a little more complicated for what you want.
First you'd want to grab the names of the input - maybe pass them through the parenthesis of your 'submit' button, which should have an onclick attribute(the submit button) to fire the javascript function. You'd then compare the value of those two inputs (document.form_name.input_name.value == etc.) If they match you've got a winner, if not return false and alert them that they must re-do the passwords.

Don't have time to write you a pseudo code atm, on my way out.

Hope this helps.

Markus.
Finally i'm seeing some light. But can ajax or javascript merged with PHP codes ?. I mean my registration page for this personal website is simple .Dun have many fields to fill in that form. what i mean is i'm using something like this right now, [php]
// Source from my test file

<?php
if (empty($_POST['emailAddress']))
{
$errors[] = 'Please enter an e-mail address';
}
else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['emailAddress']))
{
$errors[] = 'Please enter a valid e-mail address';
}

if (empty($_POST['messageBody']))
{
$errors[] = 'Please enter some message';
}
else if (strlen ($_POST['messageBody']) > 50)
{
$errors[] = 'Your message is too long, please do not submit more then 50 characters';
}

if (count($errors) == 0)
// Send E-mail .
{
bla bla bla
mail ($email, $subject, $body, $headers);
}
else
{
echo $errors[0];
}
?>
[/php]
Dec 30 '07 #3

P: 19
I believe you can merge ajax, javascript and php
Dec 30 '07 #4

Markus
Expert 5K+
P: 6,050
Post your code for the form - we can add some javascript to that page which will validate the passwords before the form is submitted.

Yes ajax, php and javascript can be used together but at this moment in time it's maybe better just to use some javascript.

:)
Dec 30 '07 #5

George Lft
P: 26
Post your code for the form - we can add some javascript to that page which will validate the passwords before the form is submitted.

Yes ajax, php and javascript can be used together but at this moment in time it's maybe better just to use some javascript.

:)
[html]
<form id="frm_submit" name="frm_submit" method="post" action="messageSent.php">
<table width="95%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td>Your E-mail Address</td>
<td><label>
<input type="text" name="emailAddress" id="emailAddress" />
</label></td>
</tr>
<tr>
<td>Re-enter your E-mail Address</td>
<td><label>
<input type="text" name="re-emailAddress" id="re-emailAddress" />
</label></td>
</tr>
<tr>
<td>Subject</td>
<td><label>
<input type="text" name="subject" id="subject" />
</label></td>
</tr>
<tr>
<td>Message Body</td>
<td><label>
<textarea name="messageBody" id="messageBody" cols="45" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<input type="submit" name="Submit" id="Submit" value="Submit" />
</label></td>
</tr>
</table>
</form>[/html]
the form may look too simple, but thats how i'm going to use it, at most i'll refine with additional fields probably future.. or not this website. So i'll just go with this form. Please help to merge with javascripts ., Thanks !
P.S. The re-enter validation here is Email address.
Dec 30 '07 #6

Markus
Expert 5K+
P: 6,050
Don't worry about it being too simple.. you're not here to impress people :P

I thought this was about validating a password? There's no password field to validate...?
Dec 30 '07 #7

George Lft
P: 26
Don't worry about it being too simple.. you're not here to impress people :P

I thought this was about validating a password? There's no password field to validate...?
Sorry my mistake- Please re-look the edited version. I have just edited . I assume validate re-entry for username will be same as password ?.

Thanks .
Dec 30 '07 #8

Markus
Expert 5K+
P: 6,050
Sorry my mistake- Please re-look the edited version. I have just edited . I assume validate re-entry for username will be same as password ?.

Thanks .
Ok so we'll be comparing the email addresses then :)

Lemme have a looksee.
Dec 30 '07 #9

Markus
Expert 5K+
P: 6,050
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  <head>
  3.   <title>Comparing the email addresses with javascript</title>
  4.  
  5. <script type="text/javascript">
  6. function compare(first, second){
  7.     var email = document.getElementById(first)
  8.     var re_email = document.getElementById(second)
  9.         if(email.value == re_email.value){
  10.             alert("Emails match");
  11.         } else {
  12.             alert("Emails don't match");
  13.         }
  14. }
  15. </script>
  16.  </head>
  17. <body>
  18. <form id="frm_submit" name="frm_submit" method="post" action="messageSent.php">
  19.   <table width="95%" border="1" cellspacing="0" cellpadding="3">
  20.     <tr>
  21.       <td>Your E-mail Address</td>
  22.       <td><label>
  23.         <input type="text" name="emailAddress" id="emailAddress" />
  24.       </label></td>
  25.     </tr>
  26.     <tr>
  27.       <td>Re-enter your E-mail Address</td>
  28.       <td><label>
  29.         <input type="text" name="re_emailAddress" id="re_emailAddress" />
  30.       </label></td>
  31.     </tr>
  32.     <tr>
  33.       <td>Subject</td>
  34.       <td><label>
  35.         <input type="text" name="subject" id="subject" />
  36.       </label></td>
  37.     </tr>
  38.     <tr>
  39.       <td>Message Body</td>
  40.       <td><label>
  41.         <textarea name="messageBody" id="messageBody" cols="45" rows="5"></textarea>
  42.       </label></td>
  43.     </tr>
  44.     <tr>
  45.       <td>&nbsp;</td>
  46.       <td><label>
  47.         <input type="button" onclick="compare('emailAddress', 're_emailAddress')" name="Submit" id="Submit" value="Submit" />
  48.       </label></td>
  49.     </tr>
  50.   </table>
  51. </form>
  52.  
It's only basic.. just the comparing of the two is done here.
Dec 30 '07 #10

George Lft
P: 26
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  <head>
  3.   <title>Comparing the email addresses with javascript</title>
  4.  
  5. <script type="text/javascript">
  6. function compare(first, second){
  7.     var email = document.getElementById(first)
  8.     var re_email = document.getElementById(second)
  9.         if(email.value == re_email.value){
  10.             alert("Emails match");
  11.         } else {
  12.             alert("Emails don't match");
  13.         }
  14. }
  15. </script>
  16.  </head>
  17. <body>
  18. <form id="frm_submit" name="frm_submit" method="post" action="messageSent.php">
  19.   <table width="95%" border="1" cellspacing="0" cellpadding="3">
  20.     <tr>
  21.       <td>Your E-mail Address</td>
  22.       <td><label>
  23.         <input type="text" name="emailAddress" id="emailAddress" />
  24.       </label></td>
  25.     </tr>
  26.     <tr>
  27.       <td>Re-enter your E-mail Address</td>
  28.       <td><label>
  29.         <input type="text" name="re_emailAddress" id="re_emailAddress" />
  30.       </label></td>
  31.     </tr>
  32.     <tr>
  33.       <td>Subject</td>
  34.       <td><label>
  35.         <input type="text" name="subject" id="subject" />
  36.       </label></td>
  37.     </tr>
  38.     <tr>
  39.       <td>Message Body</td>
  40.       <td><label>
  41.         <textarea name="messageBody" id="messageBody" cols="45" rows="5"></textarea>
  42.       </label></td>
  43.     </tr>
  44.     <tr>
  45.       <td>&nbsp;</td>
  46.       <td><label>
  47.         <input type="button" onclick="compare('emailAddress', 're_emailAddress')" name="Submit" id="Submit" value="Submit" />
  48.       </label></td>
  49.     </tr>
  50.   </table>
  51. </form>
  52.  
It's only basic.. just the comparing of the two is done here.
================================================== ===

Thanks , before i continued. Ok, the add-up is :
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3. function compare(first, second){
  4.     var email = document.getElementById(first)
  5.     var re_email = document.getElementById(second)
  6.         if(email.value == re_email.value){
  7.             alert("Emails match");
  8.         } else {
  9.             alert("Emails don't match");
  10.         }
  11. }
  12. </script>
  13.  
That's the javascript. And i dun quite understand about the bottom submit part :
Expand|Select|Wrap|Line Numbers
  1.  <input type="button" onclick="compare('emailAddress', 're_emailAddress')" name="Submit" id="Submit" value="Submit" />
it is now having javascripts function as well .?.


This will be my send-form named frm_submit. It is then processed in messageSent.php. But right now,you have entered the javascripts right into the send-form. Whereby my other php codes I shown previously is in the messageSent.php. Wow, can we place the codes at one place or something to make it shorter or neater. That's just an option If . Given a normal php validation , won't that work ?. ie . [php]
if ($_POST['emailAddress']!=$_POST['re_emailAddress'])
{
$errors[] = 'The two passwords must match';
}
[/php] i don't know why a javascript is needed. Except that we aren't able to print more than one different error at a time ?.
Dec 30 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.