Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

javascript - Email already exist in firebase database error on signing Up and stop form from submitting

I made a form and give some validations on submitting and I also want to give validation of if the email that user use in sign up is already exist or not in firebase database ,for which first I have to get the email child from database ,I already done it .The emails are printing in the console and I give variable to that specific one like

<input type="email" name="mail" id="email" placeholder="Email" />

        <p id="emailerr"></p>
ref.on('value', snapshot => {

        snapshot.forEach(function (snapChild) {

            var fireemail = snapChild.child('email').val();
            console.log(fireemail)
        })

    });

This is on submit function


function onSubmit(e) {
var check
    e.preventDefault()

if (email==fireemail){
emailerr.innerHTML='EMAIL ALREADY EXIST'
check=false;
}
if(check==false){
alert("Not submit")}
}else{
writeData(fname, email, pass, my_male, my_female)
        location.reload()
        alert('Form submitted successfully')
}

The variable fireemail is not recognise by the submit function,it gives undefined and instead of giving error it submits the form in the database


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Scope of 'fireemail' variable is not global. Declare variable outside of the function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...