Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 534059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:34:21+00:00 2026-05-13T09:34:21+00:00

For my framework I’ve written down this concept to solve the form validation problem.

  • 0

For my framework I’ve written down this concept to solve the form validation problem. I want it to be as straightforward as possible for the framework user.

Every Form (=object) has one or many FormElements (=objects). Every FormElement can have 0-n FormValidators (=objects). Everything easily configured through the backend (simple drag&drop stuff).

When the Form View is rendered, it loops over all the FormElements, and for each of them it loops over all their associated FormValidators. That way it builds up all the needed JavaScript to validate the form on client side.

A FormValidator is an lightweight object which defines only these seven things:

  • PHP class name of the validation utility class
  • method name of the validation utility class, which must be called
  • a string for additional arguments (comma-separated values)

  • JavaScript “class” name of the validation utility

  • “method” name which must be called
  • a tring for additional arguments (comma-separated values)

  • an associated ErrorInfo object which contains an formatted error message

Every of these validation methods takes as first argument an input variable with the input data. Every of these methods just check the input if it matches some rule(s), and returns TRUE or FALSE.

When the form is submitted, an FormDataManager is created and receives:
– the Form object (so it knows from where the data came from)
– the input data (typically $_POST)

It then just iterates over all the FormElements, checks all their FormValidators, and if anything is invalid, it reloads the Form which is passed the error messages array. If everything is fine, the data is further processed (i.e. stored to db).

Are there improvements in this design? Anything I’ve missed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:34:21+00:00Added an answer on May 13, 2026 at 9:34 am

    One common validation concept which I think you have missed is validation groups. For instance, you may want to cater for one of the following scenarios:

    • Form field B is mandatory only if field A has any value.
    • Form field B is mandatory only if field A has a specific value.
    • Form field B is mandatory only if field A is in a specific range (numerical or dates).
    • Either field A OR field B needs to have a value (they cannot both be empty).
    • Either field A OR field B needs to have a value (they cannot both be empty or both have a value) – (XOR).
    • Password and confirm password fields need to be equal.

    And I’m sure there are other scenarios where validation depends on the validity or optional aspect of other form elements. Also – ‘mandatory’ in the scenarios above may also be simply ‘applicable’, which would be a different situation again.
    Typical (medical system) example here is: “Are you male/female?“, with a follow-up of “Are you pregnant?” for females. Or AOP related questions, where you have the birthday and have a certain follow-up question only IF they are 65 years or older.

    It means you need some validationgroup or validation association object that contains these dependencies in a useful and generic way.

    I guess in your design it means you can also have FormValidator objects that are not directly linked to one FormElement but to a combination of FormElements and include a conditional check before triggering validation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 369k
  • Answers 369k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have discovered the fragile base class problem. One way… May 14, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer I'm not positive about XP Embedded, but on regular ol'… May 14, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer Use a custom Comparator<Date> for a TreeMap<Date,V>. Comparator<Date> ymdComparator =… May 14, 2026 at 6:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.