Skip to main content
Known Participant
August 5, 2012
Question

jquery validation engine and CF issue.

  • August 5, 2012
  • 2 replies
  • 4038 views

Hello;

I'm working on a simple coldfusion contact form. I am trying to use a jquery plug - in with it, I have the plug in working with no problem, but it won't reload the page to allow the coldfusion to execute if all fields are valid. I'm posting my code.. can anyone help me? I think I need to add a call for the page to reload with the variables to my script.. not sure how I do that.

<link rel="stylesheet" href="scripts/validationEngine.jquery.css" type="text/css"/>

<script src="scripts/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>

<script src="scripts/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>

<script src="scripts/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>

   

<script>

        function beforeCall(form, options){

            if (window.console)

            console.log("Right before the AJAX form validation call");

            return true;

        }

           

        // Called once the server replies to the ajax form validation request

        function ajaxValidationCallback(status, form, json, options){

            if (window.console)

            console.log(status);

               

            if (status === true) {

                alert("the form is valid!");

                // uncomment these lines to submit the form to form.action

                form.validationEngine('detach');

                form.submit();

                // or you may use AJAX again to submit the data

            }

        }

           

        jQuery(document).ready(function(){

            jQuery("#formID").validationEngine({

                ajaxFormValidation: true,

                onAjaxFormComplete: ajaxValidationCallback,

            });

        });

    </script

and here is what sets off the coldfusion, it's all on the same page, one page mailing it and so on..

<cfset arrErrors = ArrayNew( 1 ) >

<cfset showForm = true>

<cfif structKeyExists(form, "sendcomments")>

<!--- Create an empty error string --->

<!--- we are inserting a new record --->

<cfif NOT ArrayLen( arrErrors )>

<cfmail............

<!--- code for cfmail goes here ----->

<cfoutput>

<cfform id="formID" action="#cgi.script_name#" method="post" enctype="application/x-www-form-urlencoded">

<!--- form items --->
</cfform>

<cfelse>

thank you bla bla bla
</cfif>

that's it without getting into the form and all of that. I have the validation working, not able to send the message. I know it's because ajax/jquery aren't reloading the page, how do I make it do that?

Thank you!

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    October 25, 2012

    To enable the line form.submit() to run, shouldn't that condition be if (status) instead of if (status === true)?

    Miguel-F
    Inspiring
    August 8, 2012

    Have you already gotten this working?

    Known Participant
    August 9, 2012

    no not yet.. still pondering it. Can you help?

    Miguel-F
    Inspiring
    August 9, 2012

    Not sure, but I will try.  I'm a little confused by your description of the problem.  You are using ajax but you want the page to reload?  I assume it is making ajax calls for server-side validation and then you want the form to submit if all fields pass.  Right?

    Where in your code is the process failing?

    Are you getting your javascript alert that "the form is valid!"?

    Are you seeing your console log messages and what do they tell you?

    Need a little more info to help diagnose.