mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2026-09-03 10:21:38 -04:00
Spiffs up contact_and_edit, adding error correction and required waiver.
1). Next step will be an opt-in/out to mailman. 2). Originally this program was using google lists, but there are too many steps for users involved.
This commit is contained in:
+122
@@ -0,0 +1,122 @@
|
||||
$(function(){
|
||||
|
||||
"use strict";
|
||||
|
||||
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 last_name = $("#last_name"), last_name_error = $("#last_name_error");
|
||||
var phone = $("#phone"), phone_error = $("#phone_error");
|
||||
var email = $("#email"), email_error = $("#email_error");
|
||||
var zip = $("#zip");
|
||||
var state_abbreviation = $("#state_abbreviation");
|
||||
|
||||
// sensible defaults
|
||||
first_name.mask('#',{placeholder: "first", translation: {"#": {pattern: /[A-Za-z0-9@.]/, recursive: true} } });
|
||||
last_name.mask('#',{placeholder: "last", translation: {"#": {pattern: /[A-Za-z0-9@.]/, recursive: true} } });
|
||||
birth_date.mask("0000-00-00", {placeholder: "yyyy-mm-dd" });
|
||||
phone.mask('(000) 000-0000', {placeholder: "(000) 000-0000"});
|
||||
email.mask('#',{placeholder: "_@_", translation: {"#": {pattern: /[A-Za-z0-9@.]/, recursive: true} } });
|
||||
zip.mask('00000-0000', {placeholder: "00000-0000"});
|
||||
state_abbreviation.mask('AA',{placeholder: "WV", translation: {"A": {pattern: /[A-Za-z]/, recursive: false} } });
|
||||
$("#submit_contact").on("click keypress", function(e) {
|
||||
|
||||
// check for errors
|
||||
//error_handler(input,error_span,error,error_text,event);
|
||||
|
||||
var err0 = 0, err1 = 0;
|
||||
|
||||
// first name & last name input
|
||||
error_handler(first_name.val(), first_name_error, "","*Required",e);
|
||||
error_handler(last_name.val(), last_name_error, "","*Required",e);
|
||||
|
||||
// email and phone input
|
||||
if (email.val() === "" && phone.val() === "") {
|
||||
|
||||
error_handler(email.val(), email_error, "","*Required - email address and/or phone number",e);
|
||||
error_handler(phone.val(), phone_error, "","*Required - email address and/or phone number",e);
|
||||
|
||||
} else if ( (email.val() === "" && phone.val() !== "") ) {
|
||||
|
||||
email_error.hide();
|
||||
phone_error.hide();
|
||||
phone_validator(phone.val(),e);
|
||||
|
||||
} else if ( (email.val() !== "" && phone.val() === "") ) {
|
||||
|
||||
email_error.hide();
|
||||
phone_error.hide();
|
||||
email_validator(email.val(),e);
|
||||
|
||||
} else if ( email.val() && phone.val() ) {
|
||||
|
||||
email_error.hide();
|
||||
phone_error.hide();
|
||||
phone_validator(phone.val(),e);
|
||||
email_validator(email.val(),e);
|
||||
|
||||
}
|
||||
|
||||
// waiver checkbox
|
||||
error_handler(waiver_checkbox.prop("checked"),waiver_error,false,"*Required",event);
|
||||
|
||||
} );
|
||||
|
||||
|
||||
// waiver slideup/slidedown
|
||||
$('#waiver').hide();
|
||||
var c=0;
|
||||
$('#waiver_button').click(function(e){
|
||||
e.preventDefault();
|
||||
if (c == 0) {
|
||||
$('#waiver').slideDown();
|
||||
$(this).attr("value","Hide Waiver");
|
||||
c++;
|
||||
} else {
|
||||
$('#waiver').slideUp();
|
||||
$(this).attr("value","Show Waiver");
|
||||
c--;
|
||||
} });
|
||||
|
||||
|
||||
function phone_validator(val, e) {
|
||||
var re = /^\(\d{3}\)\s?\d{3}-\d{4}$/;
|
||||
if ( !re.test(val) ) {
|
||||
console.log("hello");
|
||||
error_handler(false, phone_error, false,"*Enter a correct phone number",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function email_validator(val, e) {
|
||||
// https://fightingforalostcause.net/content/misc/2006/compare-email-regex.php
|
||||
var re = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
|
||||
if ( !re.test(val) ) {
|
||||
error_handler(false, email_error, false,"*Enter a correct email address",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// error handler for contacts
|
||||
function error_handler(input,error_span,error,error_text,event) {
|
||||
var trans_error = 0;
|
||||
if ( input == error ) {
|
||||
if ( !error_span.is(":visible") ) {
|
||||
error_span.show();
|
||||
}
|
||||
error_span.html(error_text);
|
||||
trans_error = 1;
|
||||
} else {
|
||||
trans_error = 0;
|
||||
error_span.hide();
|
||||
}
|
||||
|
||||
if (trans_error) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
return trans_error;
|
||||
|
||||
} // end error_handling function
|
||||
|
||||
});
|
||||
+5
-16
@@ -617,7 +617,6 @@ $(function() {
|
||||
date = "0000-00-00";
|
||||
}
|
||||
|
||||
|
||||
// find new transaction_id if date has changed for a storage transaction
|
||||
// this is the most recent transaction_id
|
||||
if ($("#date_startstorage").val() && date !== "0000-00-00") {
|
||||
@@ -695,29 +694,19 @@ $(function() {
|
||||
transaction_history.push(current_transaction);
|
||||
$.post("json/transaction.php",{ history_update: 1,
|
||||
transaction_id: transaction_id,
|
||||
history: transaction_history });
|
||||
|
||||
|
||||
history: transaction_history,
|
||||
more_than_one: 1 });
|
||||
|
||||
} // more than 1 transaction in the history
|
||||
|
||||
} );
|
||||
|
||||
|
||||
} ); // check for prior transactions
|
||||
|
||||
|
||||
} // End Save History
|
||||
|
||||
|
||||
}) // end function save_and_close
|
||||
|
||||
// show history if more than 1 transaction can also be done within transactions.php &
|
||||
// choosen dis-activating active trans.
|
||||
$.post("json/transaction.php",{ history_select: 1, transaction_id: transaction_id }, function(data) {
|
||||
|
||||
if (data !== "First Transaction") {
|
||||
var transaction_history = $.parseJSON(data);
|
||||
}
|
||||
} );
|
||||
|
||||
// On reload if patron isn't logged in replace pull-down with patrons name
|
||||
if (sold_to.val() == "no_selection") {
|
||||
$.post("json/transaction.php",{ not_logged_in: 1, transaction_id: transaction_id }, function(data) {
|
||||
|
||||
Reference in New Issue
Block a user