Return the fields that do not pass validation in PHP to jQuery -
I am using jQuery with PHP for form verification. I want to return those fields which are not valid, so I can highlight them using javascript
This is my attempt to use PHP (validate.php):
& lt; Php ... $ a_invalidInput = array (); $ = $ _POST from ['to']; $ From = $ _POST ['from']; $ Email_to = $ _POST ['email_to']; If (empty (from $)) {$ a_invalidInput [] = 'to'; } If (empty ($ to)) {$ a_invalidInput [] = 'to'; } // Validate email address if (empty ($ email_to)) {$ a_invalidInput [] = 'email_to'; } Other {// More recognition for email} ...? & Gt;
This is my jquery code:
... var data = "to =" + + + "and from =" + + + " & Amp; email_ to = "+ email_to; $ .ajax ({url: "/ validate.php is included", type: "post", data: data, success: function () {// highlight field which passes verification}}); ...
I'm not sure whether I am on the right path or not and how to return the input field, which can not pass verification, so I highlighted a class I can add to this
I can use this javascript but I like to use a php file for verification
thanks Marco
One way to go is to enter a field called Jason Encoded The queen has to be returned back which does not pass.
From your PHP script, output invalid input array (Jason encoded so that your javascript could use it). Then on Javascript, you want to see if there is a value in that output. If this happens, then use it.
& lt ;? Php // at the end of your script header ('Content-Type: App / Jason'); Echo json_encode ($ a_invalidInput); Go out(); ? & Gt;
Now in your JQuery, you want to use that Jason output ...
$ Type: "Jason", Data: Data, Success: Function (Data) {if (Data! == Undefined & Data Langs gt; 0) {for (var i = 0; i
Comments
Post a Comment