+ Start a Discussion
Paul.FoxPaul.Fox 

Anyway to have CMSForce validate required fields and field types at the same time?

I have built a few web forms using CMSForce. I was able to customize the code in several places despite feeling like I was playing with one of those russian dolls (there's a component inside of a component inside of a component inside of a page inside of a page). In the end it was still easier to maintain than a custom visualforce page. The drag and drop form creation was great.

 

Anyway, my problem is that when a person submits a form on the website with some invalid field, like asdf in an email field, they get only that error message, even if they've forgotten a required field. So they fix the email address and submit it again, only to get another message that says 'xyz is a required field'.

 

It would be nicer if the user got a list of errors 'Invalid Email, xyz is a required field'.

 

Any ideas?

 

For anyone that's looking into this, it appears that the form fields are handled by the Form Field object when they're saved. That means internal salesforce code probably validates the data types. Then the RenderFormComponentController handles the required field validation, so I don't see how we could do them both at the same time, but it'd be really nice.

Best Answer chosen by Admin (Salesforce Developers) 
David VPDavid VP

Thanks for the clarification.

Your approach could work but it sure seems like a lot of work.

If you're going to modify the code that much, make sure to have a good source code versioning in place first ;-)

 

 

All Answers

David VPDavid VP

You sure seem to have gotten how CMSForce works internally ;-)

I don't have an immediate answer (when I find the time I'll look into it but it might take a while - it might be a tough one because when the custom validation fails, the record never even makes it to a real database 'save' which is when the 'wrong email format' is fired by the system).

 

For anyone else reading this : The question could be simplified and is actually :

 

'How to combine system generated validation messages with custom page messages and have them output at the same time' ?

Message Edited by David VP on 09-24-2009 09:04 AM
Paul.FoxPaul.Fox

That's what I thought, but it looks like it's the other way around.

 

It seems like Visualforce actually validates the field type when it's temporarily storing the field values using the Form_Field__c object fields. So it never makes it to the custom validation code. It would actually make more sense if it threw exceptions on required fields before throwing exceptions on the field values.

 

I don't have any validation rules, but looking at the code it looks like those would fire after checking the required fields. So you might actually be able to submit a form three times, getting a different message each time.

 

I'm thinking the only way around it would be to store everything in a text field, then convert the strings to the appropriate field types when adding it to the correct sobject. Not sure I want to modify the code that much though.

David VPDavid VP

Thanks for the clarification.

Your approach could work but it sure seems like a lot of work.

If you're going to modify the code that much, make sure to have a good source code versioning in place first ;-)

 

 

This was selected as the best answer
Paul.FoxPaul.Fox
Honestly, that is really low on my priority list and a lot of work, so I'm not sure it'll ever get done. It's not like it's letting bad records get created, it's just adding an extra step to someone already submitting a long form. I'll just cross my fingers and hope they fill it out correctly the first time.