OK.  the validation plugin is kicking my ass. as does every new thing
I try to learn.

FIRST: I need to clarify that there is a BUG up front so someone
doesn't offer it as a solution.
I am using version 1.5.5. It has a bug in the REMOTE rule/method so
this is not an option to check for duplicate entries. And I know this
because I set my lookup.php server script to a single line of ECHO
"FALSE" but the validator plugin still adds a "valid" to the element
class. Plus this was an issue in previous releases so it is more than
likely re-introduced. BUT if you think I am still wrong I am open to
suggestions so long a s they are detailed.

So with that issue behind me I went out and learned how to create a
custom method using the $.validator.addMethod() to solve my problem.
And now I have run into 2 more issues which are stopping me. If
someone can solve any 1 of these next 2 issues, I can be on my way.

1. I don't know how to grab a value returned from $.get() and put it
into a javascript variable that can be used outside the scope of the
$.get() event because I need to return that value .  I have tried
setting global variables all over the place but nothing gets set.

2. I also tried to just add an attribute to the element with the
return value, then use jquery to fetch that value. But there seems to
be a cache issue along the way. The attrib is being set correctly
(according to firebug) but the value is always 1 cycle behind. Oh...
and I do have CACHE:FALSE set.

so if anyone can help here is my code:

$.validator.addMethod("dupcheck",function(value,element){

    var lookupkey = $(element).attr("name");
    var lookupvalue = $(element).val();
    var thisid = $(element).attr("id");
    var valid_img = '<img src="/global_libs/images/icons/
checked.gif">';
    var error_img = '<img src="/global_libs/images/icons/
unchecked.gif">';

    $.get('lookup.php', {table : "members", key : lookupkey, value :
lookupvalue, successmsg:"false", failmsg:"true" }, function(data){  [I
NEED THE VALUE OF (DATA) TO BE RETURNED FROM HERE]  });
});

ok I will through in the server script as well:

here is my LOOKUP.PHP
<?

$noheaders = "true";  //prevents config.php from loading any header
data such a scripts and styles.
include("config.php");
$table = $_GET["table"];
$key = $_GET["key"];
$value = $_GET["value"];
$failmsg = (isset($_GET["failmsg"]) ? $_GET["failmsg"] : $value.": Not
Found in TABLE: ".$table." for KEY: ".$key);
$successmsg = (isset($_GET["successmsg"]) ? $_GET["successmsg"] :
$value.": Found in TABLE: ".$table." for KEY: ".$key);
$sql="SELECT * FROM $table WHERE $key='$value'" ;
$result=mysql_query($sql);
if (mysql_num_rows($result) > 0) {
  echo $successmsg;
} else {echo $failmsg;  };

?>

Thanks,
MIke

Reply via email to