Gregniuki commited on
Commit
6604c29
·
1 Parent(s): 1bd6bdb

Update templates/register.html

Browse files
Files changed (1) hide show
  1. templates/register.html +12 -22
templates/register.html CHANGED
@@ -45,43 +45,33 @@
45
  </div>
46
  <script src="https://www.google.com/recaptcha/api.js" async defer></script>
47
  <script>
48
-
49
-
50
- function validateForm() {
51
- // Here, you would put any form validation logic you need.
52
- // For demonstration purposes, let's assume it always returns true.
53
- return true;
54
- }
55
-
56
- // When the form is submitted
57
- document.getElementById('registration-form').addEventListener('submit', function(event) {
58
  event.preventDefault();
59
- // Check if all fields are filled out
60
  var username = document.getElementById('username').value;
61
  var email = document.getElementById('email').value;
62
  var password = document.getElementById('password').value;
63
  var confirmPassword = document.getElementById('confirm_password').value;
64
 
65
- // You could also check for other constraints here, like password match, etc.
66
- if(username && email && password && confirmPassword) {
67
- // All fields are filled, execute reCAPTCHA
68
  grecaptcha.execute();
69
  } else {
70
- // Not all fields are filled, perhaps show an error message or alert
71
  alert("Please fill in all required fields.");
72
  }
73
  });
74
 
75
- // Callback function to be called once reCAPTCHA is solved
76
  function onSubmit(token) {
77
- document.getElementById('recaptcha_token').value = token; // Assign the token to the hidden input
78
- document.getElementById('registration-form').submit(); // Submit the form
 
 
79
  }
80
 
81
- // When reCAPTCHA is ready, we can auto-invoke or you can bind it to a button click as well
82
- grecaptcha.ready(function() {
83
- // grecaptcha.execute(); // Uncomment this line if you want to auto-invoke reCAPTCHA
84
- });
85
  </script>
86
  </form>
87
 
 
45
  </div>
46
  <script src="https://www.google.com/recaptcha/api.js" async defer></script>
47
  <script>
48
+ document.getElementById('registration-form').addEventListener('submit', function(event) {
 
 
 
 
 
 
 
 
 
49
  event.preventDefault();
50
+
51
  var username = document.getElementById('username').value;
52
  var email = document.getElementById('email').value;
53
  var password = document.getElementById('password').value;
54
  var confirmPassword = document.getElementById('confirm_password').value;
55
 
56
+ if (username && email && password && confirmPassword) {
57
+ // If the form is valid, trigger reCAPTCHA
 
58
  grecaptcha.execute();
59
  } else {
 
60
  alert("Please fill in all required fields.");
61
  }
62
  });
63
 
 
64
  function onSubmit(token) {
65
+ document.getElementById('recaptcha_token').value = token;
66
+ if (validateForm()) {
67
+ document.getElementById('registration-form').submit();
68
+ }
69
  }
70
 
71
+ function validateForm() {
72
+ // Additional validation logic here
73
+ return true; // return false if validation fails
74
+ }
75
  </script>
76
  </form>
77