Create Account
Join Free AP Practice today
Full Name
Please enter your name
Email Address
Please enter a valid email
Password
Password is required
Confirm Password
Passwords don't match
I agree to the
Terms of Service
and
Privacy Policy
Create Account
Already have an account?
Sign in
const form = document.getElementById('registerForm'); const passwordInput = document.getElementById('password'); const confirmInput = document.getElementById('password-confirm'); const submitButton = form.querySelector('.btn-register'); form.addEventListener('submit', async function(e) { e.preventDefault(); const name = document.getElementById('name').value.trim(); const email = document.getElementById('email').value.trim(); const password = passwordInput.value; const confirmPassword = confirmInput.value; const terms = document.getElementById('terms').checked; const nameError = document.getElementById('nameError'); const emailError = document.getElementById('emailError'); const passwordError = document.getElementById('passwordError'); const confirmError = document.getElementById('confirmError'); // Reset errors [nameError, emailError, passwordError, confirmError].forEach(el => el.classList.remove('show')); let isValid = true; // Validate name if (!name) { nameError.textContent = 'Please enter your name'; nameError.classList.add('show'); isValid = false; } // Validate email const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(email)) { emailError.classList.add('show'); isValid = false; } // Validate password if (password.length < 6) { passwordError.textContent = 'Password must be at least 6 characters'; passwordError.classList.add('show'); isValid = false; } // Validate confirm password if (password !== confirmPassword) { confirmError.classList.add('show'); isValid = false; } // Validate terms if (!terms) { const termsCheckbox = document.getElementById('terms'); termsCheckbox.focus(); isValid = false; } if (isValid) { // Disable button and show loading state submitButton.disabled = true; submitButton.textContent = 'Creating Account...'; try { const data = await register(name, email, password); // Registration requires email verification: clear any token and show confirmation page if (typeof clearAuthToken === 'function') clearAuthToken(); window.location.href = '/auth/email-sent/?email=' + encodeURIComponent(email); } catch (err) { // Show error message emailError.textContent = err.message || 'Registration failed'; emailError.classList.add('show'); // Re-enable button submitButton.disabled = false; submitButton.textContent = 'Create Account'; } } });