how to create Re-enter password / Username ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • George Lft
    New Member
    • Dec 2007
    • 25

    how to create Re-enter password / Username ?

    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.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by George Lft
    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.

    Comment

    • George Lft
      New Member
      • Dec 2007
      • 25

      #3
      Originally posted by markusn00b
      Originally posted by George Lft
      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]

      Comment

      • t3chn0n3rd
        New Member
        • Dec 2007
        • 19

        #4
        I believe you can merge ajax, javascript and php

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          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.

          :)

          Comment

          • George Lft
            New Member
            • Dec 2007
            • 25

            #6
            Originally posted by markusn00b
            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_submi t" method="post" action="message Sent.php">
            <table width="95%" border="1" cellspacing="0" cellpadding="3" >
            <tr>
            <td>Your E-mail Address</td>
            <td><label>
            <input type="text" name="emailAddr ess" id="emailAddres s" />
            </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="messageBo dy" 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.

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              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...?

              Comment

              • George Lft
                New Member
                • Dec 2007
                • 25

                #8
                Originally posted by markusn00b
                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 .

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Originally posted by George Lft
                  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.

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    [code=javascript]
                    <html>
                    <head>
                    <title>Comparin g the email addresses with javascript</title>

                    <script type="text/javascript">
                    function compare(first, second){
                    var email = document.getEle mentById(first)
                    var re_email = document.getEle mentById(second )
                    if(email.value == re_email.value) {
                    alert("Emails match");
                    } else {
                    alert("Emails don't match");
                    }
                    }
                    </script>
                    </head>
                    <body>
                    <form id="frm_submit " name="frm_submi t" method="post" action="message Sent.php">
                    <table width="95%" border="1" cellspacing="0" cellpadding="3" >
                    <tr>
                    <td>Your E-mail Address</td>
                    <td><label>
                    <input type="text" name="emailAddr ess" id="emailAddres s" />
                    </label></td>
                    </tr>
                    <tr>
                    <td>Re-enter your E-mail Address</td>
                    <td><label>
                    <input type="text" name="re_emailA ddress" id="re_emailAdd ress" />
                    </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="messageBo dy" id="messageBody " cols="45" rows="5"></textarea>
                    </label></td>
                    </tr>
                    <tr>
                    <td>&nbsp;</td>
                    <td><label>
                    <input type="button" onclick="compar e('emailAddress ', 're_emailAddres s')" name="Submit" id="Submit" value="Submit" />
                    </label></td>
                    </tr>
                    </table>
                    </form>
                    [/code]
                    It's only basic.. just the comparing of the two is done here.

                    Comment

                    • George Lft
                      New Member
                      • Dec 2007
                      • 25

                      #11
                      Originally posted by markusn00b
                      [code=javascript]
                      <html>
                      <head>
                      <title>Comparin g the email addresses with javascript</title>

                      <script type="text/javascript">
                      function compare(first, second){
                      var email = document.getEle mentById(first)
                      var re_email = document.getEle mentById(second )
                      if(email.value == re_email.value) {
                      alert("Emails match");
                      } else {
                      alert("Emails don't match");
                      }
                      }
                      </script>
                      </head>
                      <body>
                      <form id="frm_submit " name="frm_submi t" method="post" action="message Sent.php">
                      <table width="95%" border="1" cellspacing="0" cellpadding="3" >
                      <tr>
                      <td>Your E-mail Address</td>
                      <td><label>
                      <input type="text" name="emailAddr ess" id="emailAddres s" />
                      </label></td>
                      </tr>
                      <tr>
                      <td>Re-enter your E-mail Address</td>
                      <td><label>
                      <input type="text" name="re_emailA ddress" id="re_emailAdd ress" />
                      </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="messageBo dy" id="messageBody " cols="45" rows="5"></textarea>
                      </label></td>
                      </tr>
                      <tr>
                      <td>&nbsp;</td>
                      <td><label>
                      <input type="button" onclick="compar e('emailAddress ', 're_emailAddres s')" name="Submit" id="Submit" value="Submit" />
                      </label></td>
                      </tr>
                      </table>
                      </form>
                      [/code]
                      It's only basic.. just the comparing of the two is done here.
                      =============== =============== =============== ========

                      Thanks , before i continued. Ok, the add-up is :
                      [code=javascript]

                      <script type="text/javascript">
                      function compare(first, second){
                      var email = document.getEle mentById(first)
                      var re_email = document.getEle mentById(second )
                      if(email.value == re_email.value) {
                      alert("Emails match");
                      } else {
                      alert("Emails don't match");
                      }
                      }
                      </script>
                      [/code]

                      That's the javascript. And i dun quite understand about the bottom submit part :
                      [code=javascript]
                      <input type="button" onclick="compar e('emailAddress ', 're_emailAddres s')" name="Submit" id="Submit" value="Submit" />[/code] 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_emailAddres s'])
                      {
                      $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 ?.

                      Comment

                      Working...