Skip to content

Commit

Permalink
Add check on email fields for sign up and contact. Refs #19
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed May 25, 2015
1 parent c5d1681 commit 552484f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
4 changes: 4 additions & 0 deletions application/views/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<input type="email" class="form-control" name="email" placeholder="Your email *">
<span class="contact-error email-error">This field is required.</span>
</div>
<div class="form-group">
<input type="email" class="form-control" name="confirmEmail" placeholder="Confirm your email *">
<span class="contact-error confirm-email-error">Your email doesn't match.</span>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="10"></textarea>
<span class="contact-error text-error">This field is required.</span>
Expand Down
4 changes: 4 additions & 0 deletions application/views/modal/sign-up.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<input type="email" class="form-control" name="email" placeholder="Enter your email" autofocus="true">
<span class="signup-error email-error"></span>
</div>
<div class="form-group">
<input type="email" class="form-control" name="confirmEmail" placeholder="Confirm your email">
<span class="signup-error confirm-email-error"></span>
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Set a password">
<span class="signup-error password-error"></span>
Expand Down
39 changes: 25 additions & 14 deletions assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,34 @@ $(document).ready(function()
$('.signup-error').hide();

var userEmail = $('input[name="email"]').val();
var confirmEmail = $('input[name="confirmEmail"]').val();
var password = $('input[name="password"]').val();
var confirmPassword = $('input[name="confirmPassword"]').val();
var mailingList = $('input[name="malingList"]').is(':checked');

if(validateEmail(userEmail))
{
if((password.length >= 6) && (password != ''))
if(userEmail == confirmEmail)
{
if(confirmPassword == password)
{
$.post('/ajax/checkEmail', {email: userEmail}, function(data)
{
var result = $.parseJSON(data);
if(result.success == true)
{
$('.stepOne').hide();
$('.stepTwo').show();
}
else
if((password.length >= 6) && (password != '')){
$.post('/ajax/checkEmail', {email: userEmail}, function(data)
{
$('.email-error').html('This email is already taken.').show();
}
});
var result = $.parseJSON(data);
if(result.success == true)
{
$('.stepOne').hide();
$('.stepTwo').show();
}
else
{
$('.confirm-email-error').html('This email is already taken.').show();
}
});
}else{
$('.password-error').html('Your password should be at least 6 characters long.').show();
}
}
else
{
Expand All @@ -90,7 +95,7 @@ $(document).ready(function()
}
else
{
$('.password-error').html('Your password should be at least 6 characters long.').show();
$('.confirm-email-error').html('Your email doesn\'t match.').show();
}

}
Expand Down Expand Up @@ -387,6 +392,7 @@ $(document).ready(function()
var name = $('input[name="name"]').val();
var email = $('input[name="email"]').val();
var message = $('textarea[name="message"]').val();
var confirmEmail = $('textarea[name="confirmEmail"]').val();
var error = false;

$('.contact-error').hide();
Expand All @@ -405,6 +411,11 @@ $(document).ready(function()
$('.text-error').show();
error = true;
}

if(confirmEmail == "" || confirmEmail != email){
$('.confirm-email-error').show();
error = true;
}

if(error === true){
return;
Expand Down

0 comments on commit 552484f

Please sign in to comment.