| Property | Type | Description |
|---|---|---|
| availableClass | string | Defaults to 'availableValue' |
| availableLabel | string | Defaults to 'is available.' |
| baseClass | string | Defaults to 'availability' |
| baseId | string | A string containing the ID of html element where the response will be placed |
| location | integer | Defaults to 1 |
| unavailableClass | string | Defaults to 'unavailableValue' |
| unavailableLabel | string | Defaults to 'is already in use.' |
| url | string | A string containing the URL to which the request is sent (Required). Defaults to 'ajax.php' |
<script type="text/javascript">
$(function(){
$('#username_1').uniqueField({
url: 'ajax.php',
baseId: 'exam_x'
});
});
</script>
<script type="text/javascript">
$(function(){
$('#username_2').uniqueField({
url: 'ajax.php',
baseId: 'exam_y'
});
$('#email').uniqueField({
url: 'ajax.php',
baseId: 'exam_z'
});
});
</script>
<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.uniquefield.js"></script> <link type="text/css" rel="stylesheet" href="css/jquery.uniquefield.css" />ajax.php
<?php
# Open a connection to a MySQL Server
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
# Select a MySQL database
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected)
{
die ('Can\'t use foo : ' . mysql_error());
}
if (isset($_POST['field']) && isset($_POST['value']))
{
$field = mysql_real_escape_string($_POST['field']);
$value = mysql_real_escape_string($_POST['value']);
$result = mysql_query("SELECT COUNT(*) AS `count`
FROM `table_users`
WHERE `$field` = '$value'
LIMIT 1",
$link) or die(mysql_error());
if (mysql_fetch_object($result)->count == 0) {
# Value is available
echo 1;
} else {
# Value is already in use
echo 0;
}
}
# Close MySQL connection
mysql_close($link);
?>
jQuery UniqueField 1.0 (03/08/2012)
Licensed under MIT and GPL
Dimitar Ivanov - Software Engineer
Follow me:
Twitter |
LinkedIn