Skip Navigation

[Gelöst] CRED form function for user to fill out only one field

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: I have two custom fields in a Form, and I would like to only allow one of the fields to be filled in. I would like to set up some form validation that prevents form submission if a User fills in values for both fields.

Solution: There are two options in our system:
- Conditional Form Groups: You can use Conditional Form Groups to show or hide the "Submit" button based on the value of these fields. If both fields are not empty, then you can hide the submit button. This is "front-end" validation, meaning that the validation occurs before the form is submitted.
- Custom validation API: You can use custom code to validate form fields on the "back-end". If errors are detected, the form will reload and display your custom error messages. This requires PHP code.

Beyond that you may be able to use custom JavaScript to handle this type of DOM manipulation.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-display-for-form-inputs/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

This support ticket is created vor 6 Jahren, 6 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von leilaG vor 6 Jahren, 6 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#906197
apply.png

versteckter Link

We have a job submission form and would like users to fill out only one of two fields, is there a way to stop the form being submitted if a user fills out both fields and making only one required?

Example fields:
Website URL or Email

#906325

Hi, we offer a couple of different options here:
- Conditional Form Groups: You can use Conditional Form Groups to show or hide the "Submit" button based on the value of these fields. If both fields are not empty, then you can hide the submit button. This is "front-end" validation, meaning that the validation occurs before the form is submitted. More info here: https://toolset.com/documentation/user-guides/conditional-display-for-form-inputs/
- Custom validation API: You can use custom code to validate form fields on the "back-end". If errors are detected, the form will reload and display your custom error messages. This requires PHP code. Documentation for the cred_form_validate API can be found here (click the orange +More button to see code samples): https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

Beyond that you may be able to use custom JavaScript to handle this type of DOM manipulation.

#906750

Thanks for the options.

If we used option 1: Conditional Form Groups, that hides the submit button if both fields are not empty, how will the user be prompted that they should only fill out one field?

And if the user left both fields empty, would it prompt the user to fill out at least one field?

#906951

It's up to you to decide how to explain things. There is no built-in prompt for this type of requirement explanation. You would have to add text in the CRED form editor that explains the requirements for your Users.

#908095

Thanks Christian, I'll try out the Conditional Form Groups.