form action with javascript

后端 未结 4 1278
半阙折子戏
半阙折子戏 2020-12-05 02:12

I have a form that must execute a javascript function on submit, the function then posts data to my php send mail file and the mail is sent. But it only works in fire fox. T

4条回答
  •  甜味超标
    2020-12-05 03:02

    A form action set to a JavaScript function is not widely supported, I'm surprised it works in FireFox.

    The best is to just set form action to your PHP script; if you need to do anything before submission you can just add to onsubmit

    Edit turned out you didn't need any extra function, just a small change here:

    function validateFormOnSubmit(theForm) {
        var reason = "";
        reason += validateName(theForm.name);
        reason += validatePhone(theForm.phone);
        reason += validateEmail(theForm.emaile);
    
        if (reason != "") {
            alert("Some fields need correction:\n" + reason);
        } else {
            simpleCart.checkout();
        }
        return false;
    }
    

    Then in your form:

提交回复
热议问题