remote2.php 943 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. // This is a sample PHP script which demonstrates the 'remote' validator
  3. // To make it work, point the web server to root Bootstrap Validate directory
  4. // and open the remote.html file:
  5. // http://domain.com/demo/remote.html
  6. //sleep(5);
  7. $valid = true;
  8. $message = '';
  9. $users = array(
  10. 'admin' => 'admin@domain.com',
  11. 'administrator' => 'administrator@domain.com',
  12. 'root' => 'root@domain.com',
  13. );
  14. if (isset($_POST['username']) && array_key_exists($_POST['username'], $users)) {
  15. $valid = false;
  16. $message = 'The username is not available';
  17. } else if (isset($_POST['email'])) {
  18. $email = $_POST['email'];
  19. foreach ($users as $k => $v) {
  20. if ($email == $v) {
  21. $valid = false;
  22. $message = 'The email is not available';
  23. break;
  24. }
  25. }
  26. }
  27. echo json_encode(
  28. $valid ? array('valid' => $valid) : array('valid' => $valid, 'message' => $message)
  29. );