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.
how to create Re-enter password / Username ?
Collapse
X
-
Tags: None
-
Originally posted by George LftIn 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.
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. -
Originally posted by markusn00bOriginally posted by George LftIn 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.
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.
// 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
-
-
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
-
Originally posted by markusn00bPost 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.
:)
<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> </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
-
Originally posted by markusn00bDon'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...?
Thanks .Comment
-
Originally posted by George LftSorry 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 .
Lemme have a looksee.Comment
-
[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> </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
-
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> </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
Comment