开发者

send email after validation

开发者 https://www.devze.com 2023-03-08 01:15 出处:网络
hi i am new enough to JavaScript and am wonder how to send details in email after validation ,heres my code

hi i am new enough to JavaScript and am wonder how to send details in email after validation ,heres my code

<script type="text/javascript"> 

 var compName=false;
 var compContry=false;
 var com开发者_如何转开发psub=false;
 var compphone=false;
 var compemail=false;


function validate_form(form)
{
    if(compName)
    {
        document.getElementById('country').focus();
        compName=true;
        if(compContry)
        {
            document.getElementById('subject').focus();
            compContry=true;
            if(compsub)
            {
                document.getElementById('Phone').focus();
                compsub=true;
                if(compphone)
                {
                    document.getElementById('email').focus();
                    compphone=true;
                    if(compemail)
                    {

                        //I just use alert to show it works. 
                        alert("Your Details Are Sent ");
                        compemail=true;
                    }
                    else
                    {
                        document.getElementById('email').focus();
                        compemail=false;
                    }
                }
                else
                {
                    document.getElementById('Phone').focus();
                    compphone=false;
                }
            }
            else
            {
                document.getElementById('subject').focus();
                compsub=false;
            }
        }
        else
        {
            document.getElementById('country').focus();
            compContry=false;
        }
    }
    else
    {
        document.getElementById('username').focus();
        compName=false;
    }

}


You need some kind of server-side scripting to send emails.


After it passes validation you can submit your form like this

document.formname.submit();

in your case, this goes at the end of your function

if (comP... == true) {
   form.submit();
}


you can add return false; after each validation if you are using cutom js for example

var first_name = $("#first_name");
        if(!$.trim(first_name.val()).length) {
            first_name.closest('.form-group').removeClass('has-success').addClass('has-error');
            return false;
        }else{
            first_name.closest('.form-group').removeClass('has-error').addClass('has-success'); 
        }

return false will stop the submit button to proceed until the form is not filled.

freelancer

0

精彩评论

暂无评论...
验证码 换一张
取 消