Browse Source

Tests to find out if a Patron's name already exists in the database.

If so, this error is produced:  Your name already exists, please choose a different middle initial.
devel
Jonathan Rosenbaum 9 years ago
parent
commit
e02e1b74d4
  1. 3
      contact_add_edit.php
  2. 16
      js/contact.js
  3. 16
      json/contact.php

3
contact_add_edit.php

@ -272,7 +272,8 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1);
<td><label class="contacts">Name:</label></td>
<td><input id="first_name" type="text" name="first_name" value="<?php echo $row_Recordset1['first_name']; ?>" size="32">
<span id="first_name_error"></span>
<input name="middle_initial" type="text" value="<?php echo $row_Recordset1['middle_initial']; ?>" size="1" maxlength="1">
<input id="middle_initial" name="middle_initial" type="text" value="<?php echo $row_Recordset1['middle_initial']; ?>" size="1" maxlength="1">
<span id="middle_initial_error"></span>
<input id="last_name" type="text" name="last_name" value="<?php echo $row_Recordset1['last_name']; ?>" size="32">
<span id="last_name_error"></span>
</td>

16
js/contact.js

@ -8,6 +8,7 @@ $(function(){
var birth_date = $("#birth_date");
var waiver_checkbox = $("#waiver_checkbox"), waiver_error = $("#waiver_error");
var first_name = $("#first_name"), first_name_error = $("#first_name_error");
var middle_initial = $("#middle_initial"), middle_initial_error = $("#middle_name_error");
var last_name = $("#last_name"), last_name_error = $("#last_name_error");
var phone = $("#phone"), phone_error = $("#phone_error");
var email = $("#email"), email_error = $("#email_error");
@ -58,7 +59,7 @@ $(function(){
// check for errors
//error_handler(input,error_span,error,error_text,event);
var err0 = 0, err1 = 0, err2 = 0, err3 = 0, err4 = 0, err5 = 0;
var err0 = 0, err1 = 0, err2 = 0, err3 = 0, err4 = 0, err5 = 0, err6 = 0;
// if it is showing
$("#email_list_error").hide();
@ -66,6 +67,17 @@ $(function(){
// first name & last name input
err0 = error_handler(first_name.val(), first_name_error, "","*Required",e);
err1 = error_handler(last_name.val(), last_name_error, "","*Required",e);
// test whether patron's name already exists
$.post("json/contact.php", {first_name: first_name.val(), middle_initial: middle_initial.val(),
last_name: last_name.val(), test_name: 1 }, function(data) {
if(data === "1") {
err6 = error_handler(0, last_name_error, "","*Your name already exists, please choose a different middle initial.",e);
}
} );
// email and phone input
if (email.val() === "" && phone.val() === "") {
@ -106,7 +118,7 @@ $(function(){
// waiver checkbox
err5 = error_handler(waiver_checkbox.prop("checked"),waiver_error,false,"*Required",e);
if ((err0 + err1 + err2 + err3 + err4 + err5) > 0 ) {
if ((err0 + err1 + err2 + err3 + err4 + err5 + err6) > 0 ) {
} else {
//e.preventDefault();

16
json/contact.php

@ -8,6 +8,22 @@ $email_list_connector_password = EMAIL_LIST_CONNECTOR_PASSWORD;
$ssl_certificate = SSL_CERTIFICATE;
// test whether patron's name already exists
if (isset($_POST['test_name'])) {
$query = 'SELECT first_name, middle_initial, last_name FROM contacts WHERE ' .
'first_name="' . $_POST['first_name'] . '" AND middle_initial="' . $_POST['middle_initial'] .
'" AND last_name="' . $_POST['last_name'] . '";';
$sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
if ( is_array($result) ) {
echo 1;
} else {
echo 0;
}
}
// update waiver
if( isset($_POST['waiver']) ) {

Loading…
Cancel
Save