Forums

Stuck on validation

nilubon03 10 Jan, 2020
Hello,

I am switching my magazine subscription form from CF4 to CF6, so I am new to CF6. The context for my question is there are three types of subscriptions; Online, Print, and Both.

If subscriber selects Online, it will disable address fields (street address, apartment, city, state/province, zip, country) and subscriber enters required fields which are name and email.

If subscriber selects Print or Both, subscriber needs to enter required fields which are name, email, street address, city, state/province, zip, and country. Apartment is optional for Print or Both subscription.

This is what I have done.
1. I enable server validations
2. I was able to set the events in the SubscriptionType field. Please see attached.



3. For street address, city, state/province, zip, and country, I set them to "Required" with Regular expression to allow some characters.

When I tested the form by selecting Online, entered information and clicked submit, I got the error message on the top of the form. I am assuming those are from "Required" that I had on Validation tab on those fields and those error message are from server side validation.



My question is how can I skip server side validation for address fields if subscriber select Online?

Thank you,

N
healyhatman 10 Jan, 2020
Don't use the server validations. Use a series of manual validations - one for all the fields that are common to all options, then an event switcher based on the subscription, with validations inside for just the relevant fields.
nilubon03 10 Jan, 2020
healyhatman,

Thank you for your suggestions.
I unchecked "Enable server validation" on Settings section.
I have Event Switcher on Submit > Actions. I plan to have server side validations inside each event as you suggested.
Then I realized I do not know a lot of things.
1. I coped the server side custom code from CF4 and put into Server side validation for Online box, but nothing happen. I mean I disabled JavaScript to test server side validation to make sure it does not allow empty fields and check the regular expression, but I did not see the error message. Basically, I do not know how to do it in CF6. Please advise.
2. What is the next action after Event switcher. How can I get to save to database and send email notification after pass the validation or if I fail the validation, how to reload the form?

Thank you for your help.

N
nilubon03 10 Jan, 2020
I think I got it. I want to double check if I am on the right track based on your suggestions above.

I have Validate Data in Online event for now.


This is what I have in the Validate Data.



Am I on the right track?

Thanks,

N
healyhatman 11 Jan, 2020
You've put a stopper in the success branch. That means if the form PASSES the validation, stop all processing.
nilubon03 14 Jan, 2020
healyhatman,

I have debugger and stopper just for testing because I want to see the form data after submitting.

I am running to another issue. Below is the Fields setup in the Validate Data action.

PrefixName/regex[/[A-Za-z\'\.\-\s]/]:Prefix contains invalid character
FirstName/required:First name is required
FirstName/regex[/[A-Za-z\'\.\-\s]/]:First name contains invalid character
LastName/required:Last name is required
LastName/regex[/[A-Za-z\'\.\-\s]/]:Last name contains invalid character
Organization/regex[/[a-zA-Z0-9\s\'\.\,\-\"\(\)]/]:Organization contains invalid character
Email/required:Email is required
Email/email:Please enter a valid email address

Since prefix and organization is optional, so I only have the regex for Prefix and Organization. When I submit the form but skip to enter Prefix and Organization, I am still stuck at the server side validation. What is the rule to allow empty value on the server side validation? I have been looking through the forum but no luck.

Please advise.

Thank you,
N
healyhatman 14 Jan, 2020
Answer
You can either put it in an event switcher with {data.empty:fieldname} and check it in the "true" branch, or you can just use PHP to validate.
nilubon03 15 Jan, 2020
Got it 😀

Thanks a bunch.
This topic is locked and no more replies can be posted.