Hey guys.
I have a form with several fields but I need only the phone number or email to be mandatory. In other words, I need to check if the email is filled in if the phone number field is not filled in or vice versa.
How to perform this validation when submitting the form?
Hi Marcos,
I don't know how to do client-side, but you can do it server-side:
- Add Condition
!$_POST.email && !$_POST.phone
- Inside Condition add step Validate Data
- Add a dummy Equal To condition, like this: (screenshot I got from other topic, ignore everything else)
(actually, in the expression typetrue
instead of{{ email }}
), so it will comparetrue
to a non-existent form field, and it will fail, so the error will be thrown
This will cause an error to be shown in the form
Thank you, always with amazing insight
Hello @Apple .
I appreciate the help.
I need to send the following fields:
NAME (required)
EMAIL (required if the PHONE field is empty)
PHONE (required if the EMAIL field is empty)
I then need to send the NAME and EMAIL or PHONE.
Hello @Quy .
I appreciate the help.
I need to send the following fields:
NAME (required)
EMAIL (required if the PHONE field is empty)
PHONE (required if the EMAIL field is empty)
I then need to send the NAME and EMAIL or PHONE.
My solution is for that.
For other fields you can put a different Validate Data step before, or click the $_POST variables directly and put there the Required rule (it's easier):
(also fill in Linked Field)
Well, I did as you advised.
But the form always informs that the email field is mandatory even when filling it out.
During the test I filled in the phone number and left the email blank. The form informs that email is mandatory.
If I fill in the email and leave the phone number blank, the form informs me that the email is mandatory.
Sorry but I didn't understand.
Hm...
I'm not sure I have time to help further, but post here the source-code of your form, and also screenshot of your Server Action. My guess is you have some HTML attribute "required" in your form.
I'm aware of a 2nd issue now, you will possibly need 2 more conditions and 1 more Validate Data step to give the proper error messages, instead of just giving error on the email form field, but that's a separate issue from what you're describing
Hey Marcos!
I think you should use in your api a combination of what @Apple and @Quy suggest. But you have to use the validation step inside an if condition
If (!$_POST.email)
Then validate name (required)
Else validate email (required)
*Of course you can add more conditions if I haven't understood correctly what exactly youe conditions
I don't have a lot of time today either, trying to get a project done by Saturday, but maybe something like this?
-Twitch
I have a complex form like this… with a random array of questions with their own required flag.
I have a datastore that I write to using logic in page flows to manage the whole required schebang.
I think you are best to manage it all on the client side and avoid calls to server actions while the form is being filled in as the server actions can fail due to users being on a mobile and losing signal etc.