Skip Navigation

[Resolved] In Toolset forms it is not possible to make taxonomy mandatory?

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Minesh 6 months ago.

Assisted by: Minesh.

Author
Posts
#2698883

Hello,

I'm having a hard time working with some Toolset forms. I am following this documentation:

https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/

I'm having trouble making category selection mandatory. According to the documentation it would be enough to add required='true' but it doesn't work

#2698922

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

To set taxonomy as required field - you will have to use the Toolset Form's hook "cred_form_validate".

More info:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

Here is the reference ticket where I mentioned the solution that will help you to fix your issue:
- https://toolset.com/forums/topic/cred-validation-of-custom-taxonomy-value/
- https://toolset.com/forums/topic/how-to-make-a-taxonomy-and-image-upload-field-required/

#2699043

Thanks, I'm analyzing the code and previous experiences

In addition to making a taxonomy mandatory, I need the user to put phones in a very specific format. For this case do I also have to use cred_form_validate?

If I'm understanding it right it sounds pretty powerful

Thanks, greetings

#2699055

Thanks for pointing me in the right direction, I was able to implement the verification I needed regarding taxonomy

The only thing is that I'm failing with the phone verification, I follow exactly the same taxonomy logic but it doesn't work for me. Am I doing something wrong regarding custom field validation?

add_filter('cred_form_validate', 'custom_field_validation', 10, 2);

function custom_field_validation($field_data, $form_data) {

$form_id = 12877;
$phone_field = 'wpcf-telefono-link';
$error_message = 'El formato del teléfono debe ser + seguido de 11 dígitos (ej. +569XXXXXXXX).';

list($fields, $errors) = $field_data;

if ($form_data['form_id'] == $form_id) {

if (isset($fields[$phone_field]['value'])) {
$phone_value = $fields[$phone_field]['value'];

if (!preg_match('/^\+\d{11}$/', $phone_value)) {

$errors[$phone_field] = $error_message;
}
}
}

return array($fields, $errors);
}

Thanks greetings

#2699100

Minesh
Supporter

Languages: English (English )

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

You do not have to write another hook for that you can combine all validation rules within the single "cred_form_validate" hook.

Can you please share problem URL where you added the form as well as admin access details and tell me where exactly you added the validation hook and what phone number I should use to validate the phone number. Please share both acceptable and not acceptable phone numbers you want to validate.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2699309

Thank you very much for the comment, I have put everything together in a single function and the verifications work without any problem

Thank you very much for the support