Skip Navigation

[Closed] Required fields not working in CRED

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 9 replies, has 3 voices.

Last updated by Minesh 6 years, 7 months ago.

Assigned support staff: Minesh.


I'm trying to make fields in one of my CRED forms required, but it's only working on the Title.

I've tried using required="true" in the field, for example: [cred_field field="type-of-technology" post="project" value="" urlparam="" required="true"] but it's not working. There's a different solution offered here: but that doesn't work either.

There's no option in the 'add field' generator to do this either.

Please can someone help me with this, as making fields required in a form is pretty essential.





Thank you for your message!

For a field you created with WP Types, you have to tick the "required" option in the field setup (see attached screenshot).

For generic fields, you will find an option for it in the modal box.

Does this help?




Thanks for the quick reply. I didn't realise these needed to be set via the Types section - that works great for most of the fields, however I'm not getting the 'required' option for a checkbox field sets I've used. Any idea how I can include these as being required?




I think you can't set a checkbox to be required because it's a binary option. The user can either select or not select this option.

Does this make sense to you?



Not really, we still want them to make a choice, and the form uses checkboxes so they can choose more than one option. We use this method with our Gravity Forms and they allow this to be a required field.




I am afraid this feature doesn't exist in Types. As a workaround, I would suggest to add a custom validation using the "cred_form_validate" filer hook:

add_filter('cred_form_validate','checkboxes_validation', 2, 10);
function checkboxes_validation( $field_data, $form_data ) {
	// field data are field values and errors
	// validate if specific form
	// if ( $form_data['id'] != 12 )
	// 		return;

 	// set error message per field
	if ( $fields['wpcf-validate-checkboxes']['value'] == '' )
		$errors['validate-checkboxes'] = 'Please enter at least one checkbox';
	return array( $fields, $errors );

You can limit this validation rule to a specific form. Change the "validate-checkboxes" field id to the one you are using for your checkboxes.

Let me know if this matches your requirements.



Hi Pierre,

Thank you for the reply - this works for one field, but when I repeat the code for a second field I get the following error on the website:

Fatal error: Cannot redeclare checkboxes_validation() (previously declared in....

Could you show me how I can include two fields in the custom function?

Thank you.



Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello Mike, this is Minesh here to help you further. I will take care of your ticket now.

As I understand you want to validate multiple fields at a same time when you submit your CRED form. Could you please confirm.

If no:
Could you please explain your issue with example or few screenshots will be helpful.



Yes that's the issue, I just need to know how to modify the code provided above to include two fields - it works with one, but I don't know how to add a second.




Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

could you please provide me some information which is the second field you want to validate as well as a link to your CRED form:

*** Please take FULL BACKUP of your database and your website.***
In order to investigate your issue if we require to check things on your install in order to see what could be going wrong there.

If you agree to this please use the form fields I have enabled below this comment box to provide temporary access details (wp-admin and FTP)?

I have set next reply as private.

The topic ‘[Closed] Required fields not working in CRED’ is closed to new replies.