PHP & JavaScript Validation Check

Started by vinodkumar, Oct 14, 2022, 03:24 AM

Previous topic - Next topic

vinodkumarTopic starter

As I create a registration form for authorization, I need to ensure that the validation check is of high quality. Although JavaScript can confirm the accuracy of filling in fields, verifying whether a user with a particular login already exists requires calling PHP code, which is accomplished through submitting the form via the POST method.

The current process successfully checks for duplicates but causes the page to refresh and update to the PHP execution directory. Ideally, the PHP check should yield the same results as the JavaScript check, instantly communicating any errors on the same page without needing to refresh it. Despite my efforts, I have not yet discovered a solution. If anyone has experience with this issue, please assist me in finding a solution.

Additional note: This is a common obstacle in web development, and there are several ways to approach it. Some solutions involve using Ajax, while others require modifying server-side scripts. It's essential to understand the underlying logic of web programming and how various languages and protocols interact with each other.
  •  

microsoftcygnet

On occasion, the browser's built-in validation may not be sufficient to ensure input data conforms to all necessary rules. To address this, developers can manually add further checks within the CustomValidation.prototype.checkValidity function.

Within the provided code, any additional requirements, such as the need for a text field to include special characters, can be included in the existing manual checks.

Despite the improved validation approach, its current implementation still has issues. The most prominent of which is that users cannot receive error messages until they click the submit form button. A superior method would involve immediate feedback as each field is filled in. This approach requires three key elements: clear and visible requirements displayed for each field prior to user input, instant feedback regarding whether input fields meet requirements, and any errors must be displayed in a way that prevents submission of an incorrectly filled form.

Additional note: Real-time validation can significantly improve user experience and streamline data entry processes. There are several ways to implement it using various technologies and techniques. However, developers must balance real-time validation with server-side validation to ensure data security.

CustomValidation.prototype.checkValidity = function(input) {

  // Here are the built-in validity checks

  // And here are special
  if (!input.value.match(/[a-z]/g)) {
    this.addInvalidity('At least 1 lowercase letter is required');
  }

  if (!input.value.match(/[A-Z]/g)) {
    this.addInvalidity('At least 1 uppercase letter is required');
  }
};


  •