Skip to content

Commit ba86d05

Browse files
committed
jquery.org/join: Client-side validation and forwarding to thank you page on success.
1 parent 6c53788 commit ba86d05

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

themes/jquery.org/style.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ ul.flex-direction-nav {
199199
font-weight: bold;
200200
}
201201

202+
.errors li {
203+
color: #a00;
204+
}
205+
202206
a.icon-search {
203207
width: 100px;
204208
height: 100px;
@@ -218,15 +222,15 @@ a.icon-search::before {
218222
color: #333333;
219223
}
220224

221-
.member-level ul {
225+
.member-level ul.gifts {
222226
float: left;
223227
list-style: none;
224228
position: relative;
225229
z-index: 2;
226230
}
227231

228-
#content .member-level ul li,
229-
#content .member-level ul li strong {
232+
#content .member-level ul.gifts li,
233+
#content .member-level ul.gifts li strong {
230234
padding-left: 0;
231235
padding-right: 15px;
232236
background: none;

themes/jquery/js/main.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ $(function() {
9494
action: StripeForm.action,
9595
nonce: StripeForm.nonce
9696
}, data )
97+
}).done(function() {
98+
window.location = "/join/thanks/";
99+
}).fail(function() {
100+
// TODO
97101
});
98102
}
99103

@@ -105,24 +109,30 @@ $(function() {
105109
email = $.trim( form.find( "[name=email]" ).val() ),
106110
address = $.trim( form.find( "[name=address]" ).val() ),
107111
gifts = form.find( "select" ),
108-
errors = [];
112+
errors = form.find( ".errors" ).empty().hide(),
113+
valid = true;
114+
115+
function showError( msg ) {
116+
$( "<li>" ).text( msg ).appendTo( errors );
117+
valid = false;
118+
}
109119

110120
// Verify all fields
111121
if ( name.length < 3 ) {
112-
errors.push( "Please provide your full name." );
122+
showError( "Please provide your full name." );
113123
}
114124
if ( email.length < 7 ) {
115-
errors.push( "Please provide a valid email address" );
125+
showError( "Please provide a valid email address" );
116126
}
117127
if ( address.length < 10 ) {
118-
errors.push( "Please provide your full address." );
128+
showError( "Please provide your full address." );
119129
}
120130
if ( gifts.filter(function() { return !$( this ).val(); }).length ) {
121-
errors.push( "Please choose a size for each gift." );
131+
showError( "Please choose a size for each gift." );
122132
}
123133

124-
// TODO: error handling
125-
if ( errors.length ) {
134+
if ( !valid ) {
135+
errors.slideDown();
126136
return;
127137
}
128138

0 commit comments

Comments
 (0)