Make sometimes hidden fields required

Make sometimes hidden fields required

mfitportalmfitportal Posts: 12Questions: 5Answers: 0

For the editor that I am using, only certain fields show if they are enabled in the setting page. I am unsure of how to make them required when they aren't hidden. I've tried on the editor have the attr part and make the field required set to true, however it doesn't seem to do anything as I can leave it empty and it still submits the values to the database. Its only in the server side script when I use a validator::notEmpty it makes it required. However it should validate only when the field isn't empty. Is there a way in the server side script to check what the field type is?

This question has an accepted answers - jump to answer


  • allanallan Posts: 48,657Questions: 1Answers: 7,068 Site admin
    Answer ✓

    The key thing to keep in mind here is that you need the validation to occur at the server-side. You can do client-side validation, but you must also do server-side since it is trivial to bypass client-side validation from any form - including Editor's.

    So on the server-side, you need to have the knowledge of if the field is required or not. Is that information in a session variable, the database, or something else? Either way, I would suggest using an event handler on the server-side to add the validation you need to the fields, based on whatever the configuration is (i.e. read the db and then apply the validation as needed).


  • mfitportalmfitportal Posts: 12Questions: 5Answers: 0

    Yeah that works, I saw that one of the other developers definded a presubmit function to check for validation. Thank you.

Sign In or Register to comment.