1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to make .js file to load verification file?

Discussion in 'General Programming Chat' started by Husbarn, Sep 18, 2014.

  1. Husbarn

    Husbarn Junior Member

    Joined:
    Dec 19, 2012
    Messages:
    160
    Likes Received:
    20
    I have a script which verifies from a .js file if something is typed correctly. I want to add another code to that script and i have a file verify.php which I want to load from a .js file. Verify.php verifies if my newly added line is correct, but it must be verified from a .PHP file. So I need something to "redirect" that verification through a .js file.

    Any ideas on this?
     
    Last edited: Sep 18, 2014
  2. Arbvestor

    Arbvestor Newbie

    Joined:
    Feb 11, 2014
    Messages:
    25
    Likes Received:
    15
    Occupation:
    Support Tech
    Location:
    Spain
    Home Page:
    Where do you want the verification to take place? On the client or on the server or both? Client side you can't run PHP, only JavaScript. On the server you can run both, but usually not at the same time. PHP you would chose in an environment like Apache/PHP. The JavaScript solution would be most likely be based on a Nodejs webserver.

    Can you elaborate what you exactly want to do?
     
  3. Husbarn

    Husbarn Junior Member

    Joined:
    Dec 19, 2012
    Messages:
    160
    Likes Received:
    20
    This is .js file:

    Code:
    $(document).ready(function () {
        function u() {
            if ($("#agt_mail_name").val() == "") {
                t.addClass("error");
                n.text("Please Enter Your Name");
                n.addClass("message_error2");
                return false
            } else {
                t.removeClass("error");
                n.text("");
                n.removeClass("message_error2");
                return true
            }
        }
        function a() {
            var e = 0;
            if ($("#agt_mail_email").val() == "") {
                e = 1
            } else if ($("#agt_mail_email").val() != "") {
                var t = $("#agt_mail_email").val();
                var n = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
                if (n.test(t)) {
                    e = 0
                } else {
                    e = 1
                }
            }
            if (e) {
                r.addClass("error");
                i.text("Please Enter valid Email Address");
                i.addClass("message_error2");
                return false
            } else {
                r.removeClass("error");
                i.text("");
                i.removeClass("message_error");
                return true
            }
        }
        function f() {
            if ($("#agt_mail_msg").val() == "") {
                s.addClass("error");
                o.text("Please Enter Comments");
                o.addClass("message_error2");
                return false
            } else {
                s.removeClass("error");
                o.text("");
                o.removeClass("message_error2");
                return true
            }
        }
        function l() {
            document.getElementById("agt_mail_name").value = "";
            document.getElementById("agt_mail_email").value = "";
            document.getElementById("agt_mail_phone").value = "";
            document.getElementById("agt_mail_msg").value = ""
        }
        var e = $("#agt_mail_agent");
        var t = $("#agt_mail_name");
        var n = $("#span_agt_mail_name");
        var r = $("#agt_mail_email");
        var i = $("#span_agt_mail_email");
        var s = $("#agt_mail_msg");
        var o = $("#span_agt_mail_msg");
        t.blur(u);
        r.blur(a);
        s.blur(f);
        t.keyup(u);
        r.keyup(a);
        s.keyup(f);
        e.submit(function () {
            if (u() & a() & f()) {
                return true
            } else {
                return false
            }
        })
    })
    It verifies if everything is typed correctly in a inquiry form. So if you type something wrong, it won't allow to send an inquiry.

    I want to add a code which could verify "verify.php" file through it (trying to install google recaptcha). So basically I need this file to verify "verify.php" file and if captcha is typed correctly, it could allow an inquiry to be sent.
     
  4. cleanguy2

    cleanguy2 Jr. VIP Jr. VIP

    Joined:
    Jan 28, 2013
    Messages:
    128
    Likes Received:
    19
    If I understood correctly you are looking for ajax

    http://api.jquery.com/jquery.ajax/

    On the other side I know you can implement recaptcha without ajax too.

    You should implement checking in your submit.php or whatever (where actually inquiry gets saved)
     
  5. Magic5

    Magic5 BANNED BANNED

    Joined:
    Aug 30, 2014
    Messages:
    376
    Likes Received:
    83
    Why do u want a java file to do this pretty sure this can be done within php right?
     
  6. mnunes532

    mnunes532 Power Member

    Joined:
    Jan 21, 2014
    Messages:
    721
    Likes Received:
    180
  7. Husbarn

    Husbarn Junior Member

    Joined:
    Dec 19, 2012
    Messages:
    160
    Likes Received:
    20
    Yes, but the problem is that I don't know how. Any ideas would be appreciated. :)