Skip to content

fix: enterprise form validation (#2189) #2190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Mohit5Upadhyay
Copy link

What does this PR do?

This PR fixes: #2189 the validation logic in the enterprise form to ensure that input values are properly trimmed before validation checks. Previously, there was NO data validation, even the whitespace is also consider as legitimate data.

Test Plan

Changes included in this PR:

  • Updated validation logic in +page.svelte for the enterprise form to provide form validation

Manually tested the enterprise form by:

  • by filling the details void values the proper validation occur and proper error seen.

Update

form-validation.mp4

Related PRs and Issues

Closes #2189

Have you read the Contributing Guidelines on issues?

Yes

Copy link

appwrite bot commented Jul 16, 2025

appwrite.io

Project ID: 684969cb000a2f6c0a02

Sites (1)
Site Status Logs Preview QR
 website
68496a17000f03d62013
Failed Failed Authorize Preview URL QR Code

Note

Cursor pagination performs better than offset pagination when loading further pages.

@Mohit5Upadhyay
Copy link
Author

hi @sara-k-48 @tomer @stnguyen90 👋,

This PR addresses issue #2189 by improving the validation logic in the enterprise form to handle Inputs

Please review the changes when you get a chance.
If there's anything that needs to be tweaked or adjusted,
Please let me know — I'm happy to make the updates promptly.

Thanks for your time and feedback! 🙌

@coolify-appwrite-org
Copy link

coolify-appwrite-org bot commented Jul 16, 2025

The preview deployment failed. 🔴

Open Build Logs

Last updated at: 2025-07-29 14:37:54 CET

@ChiragAgg5k ChiragAgg5k requested a review from Copilot July 28, 2025 11:16
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes form validation in the enterprise contact form to prevent submission of empty or whitespace-only fields and ensures proper data sanitization. Previously, the form had no validation and would accept whitespace as legitimate data.

  • Added comprehensive validation logic to check for required fields and text-only constraints
  • Implemented trimming of input values before validation and submission
  • Added specific error messages for empty fields and numeric-only inputs in text fields


for (const field of validationRules.textOnly) {
const trimmedValue = field.value.trim();
if (/^\d+$/.test(trimmedValue)) {
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex /^\d+$/ only validates that the field contains only digits, but this would also reject valid company names like '3M' or '7-Eleven'. Consider using a more specific validation or clarifying the business requirement for this constraint.

Suggested change
if (/^\d+$/.test(trimmedValue)) {
if (!/\D/.test(trimmedValue)) {

Copilot uses AI. Check for mistakes.

Comment on lines 30 to 48
const validationRules = {
required: [
{ value: firstName, name: 'First name' },
{ value: lastName, name: 'Last name' },
{ value: email, name: 'Email' },
{ value: companyName, name: 'Company name' },
{ value: companyWebsite, name: 'Company website' },
{ value: useCase, name: 'Use case' }
],
textOnly: [
{ value: firstName, name: 'First name' },
{ value: lastName, name: 'Last name' },
{ value: companyName, name: 'Company name' },
{ value: useCase, name: 'Use case' }
]
};

for (const field of validationRules.required) {
const trimmedValue = field.value.trim();
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same field values are being trimmed multiple times in different validation loops. Consider trimming all values once at the beginning and storing them in variables to avoid redundant operations.

Suggested change
const validationRules = {
required: [
{ value: firstName, name: 'First name' },
{ value: lastName, name: 'Last name' },
{ value: email, name: 'Email' },
{ value: companyName, name: 'Company name' },
{ value: companyWebsite, name: 'Company website' },
{ value: useCase, name: 'Use case' }
],
textOnly: [
{ value: firstName, name: 'First name' },
{ value: lastName, name: 'Last name' },
{ value: companyName, name: 'Company name' },
{ value: useCase, name: 'Use case' }
]
};
for (const field of validationRules.required) {
const trimmedValue = field.value.trim();
const trimmedFirstName = firstName.trim();
const trimmedLastName = lastName.trim();
const trimmedEmail = email.trim();
const trimmedCompanyName = companyName.trim();
const trimmedCompanyWebsite = companyWebsite.trim();
const trimmedUseCase = useCase.trim();
const validationRules = {
required: [
{ value: trimmedFirstName, name: 'First name' },
{ value: trimmedLastName, name: 'Last name' },
{ value: trimmedEmail, name: 'Email' },
{ value: trimmedCompanyName, name: 'Company name' },
{ value: trimmedCompanyWebsite, name: 'Company website' },
{ value: trimmedUseCase, name: 'Use case' }
],
textOnly: [
{ value: trimmedFirstName, name: 'First name' },
{ value: trimmedLastName, name: 'Last name' },
{ value: trimmedCompanyName, name: 'Company name' },
{ value: trimmedUseCase, name: 'Use case' }
]
};
for (const field of validationRules.required) {
const trimmedValue = field.value;

Copilot uses AI. Check for mistakes.

Comment on lines 42 to 43
{ value: companyName, name: 'Company name' },
{ value: useCase, name: 'Use case' }
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including 'Use case' in the textOnly validation seems inappropriate as use cases could legitimately contain numbers (e.g., 'Support for 1000+ users'). Consider removing this field from the textOnly validation rules.

Suggested change
{ value: companyName, name: 'Company name' },
{ value: useCase, name: 'Use case' }
{ value: companyName, name: 'Company name' }

Copilot uses AI. Check for mistakes.

@ChiragAgg5k
Copy link
Member

@Mohit5Upadhyay copilot has suggested some good changes, can you please take a look

@Mohit5Upadhyay
Copy link
Author

hi @ChiragAgg5k ,
I've pushed the updated changes with improved validation logic as per the suggested review.
Please have a look and let me know if anything else needs to be adjusted.
Thanks!

@ChiragAgg5k
Copy link
Member

@Mohit5Upadhyay also dont forget to run format command, tests are failing

@Mohit5Upadhyay
Copy link
Author

Apologies @ChiragAgg5k 🙏
Just noticed.

@Mohit5Upadhyay also dont forget to run format command, tests are failing

I run the format command and push the changes. Let me know if anything else needed.
Thanks for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Validation is not properly handled in the enterprise form.
2 participants