Skip Navigation

[Closed] Making custom field only required upon user registration

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.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 1 year, 9 months ago.

Author
Posts
#2579251

I have created a number of custom user fields that are required upon registration with a user form. It works well for new users but I don't expect pre-existing users to also have these fields. Is there a way to only make the custom fields required on the registration (user form) page but not required elsewhere (so for the admin or for previous users who want to edit their details)?

#2579271

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

The required-ness of fields is ordinarily set within Types, where the custom fields are set up. That is effective when editing posts or users (in this case) in the back end, and is inherited by Forms that use those same fields on the front end.

If you don't want the fields to be required on the back end then there is no alternative but to edit the custom field settings and remove the required setting.

Then the fields will not be required in your front end forms.

To make them required you have two options.

One is to mark them as required (e.g. with an asterix on the field label) and then use server-side processing to validate the fields upon submission (using the cred_form_validate hook, see the examples here: https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate).

A second is to add some JS to your form to update the form inputs to add a required attribute to them. (If it really is important that users supply values for these required fields you may want to combine this with the server-side validation, to prevent users from removing the required attribute manually with the browser dev tools.)

The topic ‘[Closed] Making custom field only required upon user registration’ is closed to new replies.