Skip Navigation

[Resolved] Taxonomies and post content description required in post form

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by markP-19 1 year, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2508039

Hi

I'm trying to make my taoxonomies and post content description required in my post form using this snippet, but it isn't working. Correct post form ID and slugs are in use:

function tssupp_require_sector($field_data, $form_data) {

// Split $field_data into separate $fields and $errors
list( $fields,$errors ) = $field_data;

// validate specific form
if ( $form_data['id']==107166) {

// check at least one of required taxonomies set
if ( empty( $fields['cv-arbejdstid']['value'] ) && empty( $fields['cv-arbejdsvilkar']['value'] ) && empty( $fields['cv-aktiv-jobsogende']['value'] ) && empty( $fields['cv-foretrukken-branche']['value'] ) ) {

$errors['cv-arbejdstid'] = 'You must choose at least one sector';
}
}

return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'tssupp_require_sector', 10, 2 );

Regards

#2509441

Hi,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot this, I'll need to see exactly how this form and the taxonomies are set up in the admin area.

Can you please share temporary admin login details, along with the link to the page, where this form can be seen?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2511673

Thank you for sharing the access details.

I couldn't find the custom code snippet for the form validation, anywhere on the website, so it seems like it has been removed.

You can use the slightly updated code, that handles the validation for each of those 4 taxonomies and the post content, separately:


function tssupp_require_sector($field_data, $form_data) {

	// Split $field_data into separate $fields and $errors
	list( $fields,$errors ) = $field_data;

	// validate specific form
	if ( $form_data['id']==107166 ) {
		
		// check at least one of required taxonomies set: cv-arbejdstid
		if ( empty($fields['cv-arbejdstid']['value']) ) {
			$errors['cv-arbejdstid'] = 'You must choose at least one sector';
		}

		// check at least one of required taxonomies set: cv-arbejdsvilkar
		if ( empty($fields['cv-arbejdsvilkar']['value']) ) {
			$errors['cv-arbejdsvilkar'] = 'You must choose at least one sector';
		}

		// check at least one of required taxonomies set: cv-aktiv-jobsogende
		if ( empty($fields['cv-aktiv-jobsogende']['value']) ) {
			$errors['cv-aktiv-jobsogende'] = 'You must choose at least one sector';
		}

		// check at least one of required taxonomies set: cv-foretrukken-branche
		if ( empty($fields['cv-foretrukken-branche']['value']) ) {
			$errors['cv-foretrukken-branche'] = 'You must choose at least one sector';
		}

		// check that some post content is set: post_content
		if ( empty($fields['post_content']['value']) ) {
			$errors['post_content'] = 'Content cannot be empty';
		}
	}

	return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'tssupp_require_sector', 10, 2 );

Feel free to change the validation messages for each field, as needed.

#2513781

My issue is resolved now. Thank you!