Hi,

I am fairly new to jquery,  jquery validation and competely new to
JSON. I was wondering if anyone could provide or point me to an
example of a use of the remote method of the validation plugin that
can display the error message returned by the remotely called php
file.

I have an input field wherein someone enters an id to a database
table, specifically an id called media_id. I have the remote method
set up to call a php script (check_database.php)  that looks for that
media_id in my database. There are a number of reasons that search
might fail: the id might not exist, or it might exist but have a
certain invalid status, etc. I would like to be able to display a
message specific to the problem rather than one generic "That id is
invalid" message. I read that my php script could return a json
formatted message, but I am not sure how to do that, or how to modify
the javascript to handle what it gets back. I would appreciate any
help!

my starting point in my javascript file:

 rules: {
            media_id: {
               required: true,
               remote: 'check_database.php'
            }
         },

summary of what I am trying to do in check_database.php:

database query with media_id
if no errors
   return "true"
else if  error 1
  return ???
else if error 2
  return  ???
etc.

Reply via email to