Sunday, 15 May 2011

php - Javascript Validation in WordPress not working for Google form -


My goal was to redirect the user after filling out Google Form on Wordpress. I have managed to do this and with CSS The form is relaxed. I have used the following tutorials:

The problem is that I can not get my custom JavaScript recognition to work in WordPress. I have tested the code locally and have repeated it.

& lt; Body & gt; & Lt; H1 id = "heading" & gt; This key form is a test & lt; / H1> & Lt; Form action = "http://www.wikipedia.org" method = "received" onsubmit = "return (valid ());" & Gt; & Lt; Ul id = "special-list" & gt; & Lt; Li & gt; First name: & lt; Input type = "text" name = "entry.198534167" value = "" & gt; & Lt; / Li & gt; & Lt; Li & gt; Last name: & lt; Input type = "text" name = "," entry .641095175 "value =" "& gt; & lt; / li & gt;
  • Input type =" radio "name =" gender "Man" = "Male" was checked> Male
  • Input type = "Radio" name = "gender" value = "woman" & gt; female and ;

    Javascript:

      var errors = []; validate the function () {var check_name = / ^ [A-GAA-Z] {2 , 30} $ /; var element = ["entry.198534167", "p. Register .6410 9 517 "]; var first_name = document.forms [0] .elements [0] .value; var last_name = document.forms [0] .elements [1] .value; if (! Check_name test (first_name )) {Errors [errors.length] = "Your first name was not entered correctly. Use letters as A-Z"; Document.forces [0] .elements [0]. Focus ();} If (! Check_name test (last_name)) {errors [errors.length] = "Your last name was not entered correctly. (ARR (error)); Return Return;} Return Correct;} Function Report Errors (Errors) {var msg = "Please enter valid data ... for" N "; (var i = 0; i & lt; errors.length; i ++ } {NumError = i + 1; msg + = "\ n" + numError + "" + error [i];} alert (msg);}  

    I head over my javascript file I tried to add in, enqueue in my child's theme functions php file and finally the main part of the page template file.

    Finally, I know that my javascript page h Because this developer tool appears in the list of resources. I have also used a warning message that works on the document is ready. However, verification still does not work.

  • After running my javascript through jslint and ensuring that there were no fatal flaws, I found my error in the html form. Worked in code given in JSFDial Because the function was given in validate () form attribute onsubmit = "" .

    In the html on the WordPress, I onsubmit = "submitted = true;" Was . I believe this was a code copied from Google Form. My Bela was the right HTML (I did not need ; ) and th e WordPress code I was wrong.


    No comments:

    Post a Comment