...

View Full Version : Mistake? careless?



rockbluster
07-22-2009, 07:41 PM
When i try to enter different password in my form, "Confirmation password is different" popped up, but it still submit the form.
Any idea what's wrong?


<script type="text/javascript">

dojo.require("dojo.parser");
dojo.require("dijit.form.ValidationTextBox");
dojo.require ("dijit.form.Form");
dojo.require("dijit.form.CheckBox");
dojo.require ("dijit.form.FilteringSelect");
dojo.require ("dijit.form.TextBox");


function checkPw(formFields) {
if (formFields.confirmuPass != formFields.uPass2)
alert("Confirmation password is different.");


}



function submitIfValid(valid)
{
if (valid) {
document.signup.submit()
} else {
alert('Not all fields are valid');

}
}

function both(formfields, valid) {
checkPw(formfields);
submitIfValid(valid);

}

</script>

and this is my form.


<form name="signup" dojotype="dijit.form.Form" action = 'do_signup.php' method='post'
enctype='multipart/form-data' execute="both(arguments[0], this.isValid());">

<tr>
<td>Password</td>
<td><input type = 'password' name = 'uPass'
dojoType="dijit.form.ValidationTextBox"

required="true"
invalidMessage="Please type a password" />*</td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type = 'password' name = 'uPass2'
dojoType="dijit.form.ValidationTextBox"
required="true"
invalidMessage="Please confirm your password" />*</td>
</tr>



Help appreciated.

ckeyrouz
07-22-2009, 07:49 PM
YOu have to change your function like this:


function checkPw(formFields)
{
if (formFields.confirmuPass != formFields.uPass2)
{
valid = false;
alert("Confirmation password is different.");
}


}

I suppose that you have created a global variable named valid that you are retrieving using the method isValid();

When the validation is not complete make sure to set it to false.

Philip M
07-22-2009, 07:50 PM
alert("Confirmation password is different.");
return false;



It is your responsibility to die() if necessary….. - PHP Manual

Amphiluke
07-22-2009, 07:51 PM
function checkPw(formFields) {
if (formFields.confirmuPass != formFields.uPass2) {
alert("Confirmation password is different.");
return false;
} else {
return true;
}
}

...............

function both(formfields, valid) {
if (checkPw(formfields))
submitIfValid(valid);
}


P.S. O, I'm third in order... =)

ckeyrouz
07-22-2009, 07:56 PM
To be done in a more accurate way, I would take the code of Amphiluke and change it to this:

function checkPw(formFields) {
if (formFields.confirmuPass != formFields.uPass2) {
alert("Confirmation password is different.");
return false;
} else {
return true;
}
}

...............

function both(formfields, valid)
{
submitIfValid(checkPw(formfields));
}

rockbluster
07-22-2009, 08:05 PM
Hi guys, thanks for replying.
Unfortunately, it's still not working.

This time, the form will not submit when the password is wrong, but when the password matches, "Confirmation password is different." still pops out.

MattF
07-22-2009, 08:12 PM
Should this:



if (formFields.confirmuPass != formFields.uPass2) {


not be:



if (formFields.uPass != formFields.uPass2) {

rockbluster
07-22-2009, 08:23 PM
Should this:



if (formFields.confirmuPass != formFields.uPass2) {


not be:



if (formFields.uPass != formFields.uPass2) {


Thats right. i put



if (formFields.confirmuPass != formFields.uPass2) {

ckeyrouz
07-22-2009, 08:27 PM
Your code should be like this:


if (formFields.uPass.value != formFields.uPass2.value) {

rockbluster
07-22-2009, 08:36 PM
Your code should be like this:


if (formFields.uPass.value != formFields.uPass2.value) {

After i try changing to yours, the form submitted even though the password is different.

ckeyrouz
07-22-2009, 08:40 PM
So many changes where done.
Could you please post the latest code you have?

rockbluster
07-22-2009, 08:44 PM
Right now :



<script type="text/javascript">

dojo.require("dojo.parser");
dojo.require("dijit.form.ValidationTextBox");
dojo.require ("dijit.form.Form");
dojo.require("dijit.form.CheckBox");
dojo.require ("dijit.form.FilteringSelect");
dojo.require ("dijit.form.TextBox");


function checkPw(formFields) {
if (formFields.confirmuPass != formFields.uPass2) {
alert("Confirmation password is different.");
return false;
} else {
return true;
}
}




function submitIfValid(valid)
{
if (valid) {
document.signup.submit()
} else {
alert('Not all fields are valid');

}
}

function both(formFields, valid)
{
submitIfValid(checkPw(formFields));
}

</script>

Philip M
07-22-2009, 08:48 PM
var valid = true;
function checkPw(formFields) {
if (formFields.confirmuPass != formFields.uPass2) {
alert("Confirmation password is different.");
valid = false;
}
return valid;
}

function submitIfValid(valid) {
if (valid) {
document.signup.submit();
}
else {
alert('Not all fields are valid');
return false;
}
}

rockbluster
07-22-2009, 08:59 PM
var valid = true;
function checkPw(formFields) {
if (formFields.confirmuPass != formFields.uPass2) {
alert("Confirmation password is different.");
valid = false;
}
return valid;
}

function submitIfValid(valid) {
if (valid) {
document.signup.submit();
}
else {
alert('Not all fields are valid');
return false;
}
}



hmmmm...... It is still not working.

ckeyrouz
07-22-2009, 09:07 PM
where is the html object named confirmuPass .
Cannot see it in the code you posted.

MattF
07-22-2009, 09:11 PM
I still cannot see anywhere where you have the confirmuPass field defined. uPass and uPass2, yes, but not confirmuPass. I've either got ball bearings for eyes or I'm missing something.

Edit: Beaten to the post again. :D

Philip M
07-22-2009, 10:35 PM
It should be upass .......

Rockbluster - do try a little self-help. Put some temporary alerts in to see what is happening:-


var valid = true;
function checkPw(formFields) {

alert (formFields.uPass);
alert (formFields.uPass2);

if (formFields.uPass != formFields.uPass2) {
alert("Confirmation password is different.");
valid = false;
}
return valid;
}

rockbluster
07-23-2009, 06:22 AM
where is the html object named confirmuPass .
Cannot see it in the code you posted.


I still cannot see anywhere where you have the confirmuPass field defined. uPass and uPass2, yes, but not confirmuPass. I've either got ball bearings for eyes or I'm missing something.

I didn't realise until you guys mention it. I suppose the password checking is fine now, it wouldn't submit now.


<script type="text/javascript">

dojo.require("dojo.parser");
dojo.require("dijit.form.ValidationTextBox");
dojo.require ("dijit.form.Form");
dojo.require("dijit.form.CheckBox");
dojo.require ("dijit.form.FilteringSelect");
dojo.require ("dijit.form.TextBox");


var valid = true;
function checkPw(formFields) {

//alert (formFields.uPass);
//alert (formFields.uPass2);

if (formFields.uPass !== formFields.uPass2) {
alert("Confirmation password is different.");
valid = false;
}
return valid;
}

function submitIfValid(valid) {
if (valid) {
document.signup.submit();
return true;
}
else {
alert('Not all fields are valid');
return false;
}
}

function both(formFields, valid)
{
submitIfValid(checkPw(formFields));
}

</script>

rockbluster
07-23-2009, 12:00 PM
Now when i did not enter any field, the form will still submit.


<script type="text/javascript">

dojo.require("dojo.parser");
dojo.require("dijit.form.ValidationTextBox");
dojo.require ("dijit.form.Form");
dojo.require("dijit.form.CheckBox");
dojo.require ("dijit.form.FilteringSelect");
dojo.require ("dijit.form.TextBox");



function checkPw(formFields) {

//alert (formFields.uPass);
//alert (formFields.uPass2);
var valid = true;
if (formFields.uPass != formFields.uPass2) {
alert("Confirmation password is different.");
valid = false;
}

return valid;
}

function submitIfValid(valid) {
if (valid) {
document.signup.submit();
return true;
}
else {
alert('Not all fields are valid');
return false;
}
}

function both(formFields, valid)
{
submitIfValid(checkPw(formFields));
}

</script>

ckeyrouz
07-23-2009, 03:30 PM
change your function like this:

function checkPw(formFields) {

//alert (formFields.uPass);
//alert (formFields.uPass2);
var valid = true;
if (formFields.uPass != formFields.uPass2 && formFields.uPass2 != "") {
alert("Confirmation password is different.");
valid = false;
}

rockbluster
07-23-2009, 06:21 PM
Now the problem is that when i insert all the fields, it will not submit if the password validation is wrong. Whereas if nothing is inserted into the fields, the form will submit.

ckeyrouz
07-23-2009, 06:50 PM
try this:


function checkPw(formFields) {

//alert (formFields.uPass);
//alert (formFields.uPass2);
var valid = true;
if (formFields.uPass != formFields.uPass2 )
{
alert("Confirmation password is different.");
valid = false;
}
else if (formFields.uPass == "" || formFields.uPass2 == "")
{
alert("Password field cannot be blank");
valid = false;
}

rockbluster
07-24-2009, 09:41 AM
Cool. Its working now. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum