Skip Navigation

[Resolved] Condition on Required Field

This support ticket is created 3 years, 10 months ago. 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.

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 6 replies, has 2 voices.

Last updated by irfanA 3 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1902211

Tell us what you are trying to do?

I have front end Post Form with custom Filed Phone, Whatsapp and Email non of them is Required but I want to customer to mention at least one therefor need some of your help

Condition (Required):
Phone or Email or Whatsapp

Is there any documentation that you are following?

Not yet

Is there a similar example that we can see?

I hope you got what I want if still need some help just let me know.

What is the link to your site?

hidden link

#1902269

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

You can use the Toolset Form hook: cred_form_validate to validate your form.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

Please check the Usage example and adjust your code accordingly.

#1902319

Opps thank you Mensh but though I am not a programmer could you just give me an example what will be my code and where I have to put.

#1902341

Minesh
Supporter

Languages: English (English )

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

You can add the code to the "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

Here is the sample example:
- https://toolset.com/documentation/adding-custom-code/require-at-least-one-checkbox-of-a-checkboxes-field-to-be-checked-in-a-toolset-form/

If you still do not know how to do it, please let me know your form field slugs for phone, email or whatsapp.

#1902723

Sorry it is bit complicated.
Below are the fields:

Phone: phone-number
Whatsapp:wpcf-whatsapp-link
Email: e-mail

And do let me know where I have to paste that code

#1903513

Minesh
Supporter

Languages: English (English )

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

Please try to add the following code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_filter('cred_form_validate','func_validate_my_form',10,2);
function func_validate_my_form($error_fields, $form_data) {
 
   //field data are field values and errors
    list($fields,$errors)=$error_fields;
 
    if ($form_data['id']==99999) {
        
        if (empty($fields['wpcf-phone-number']['value']) and empty($fields['wpcf-whatsapp-link']['value']) and empty($fields['wpcf-e-mail']['value']) ) {
         
            $errors['wpcf-phone-number']='Please enter value for at least Phone,Email, Whatsapp';
        }
    }
    //return result
    return array($fields,$errors);
}

Where:
- Replace 99999 with your original form ID
- please replace field slug if required and error message.

If it does not work, please share problem URL where you added your form as well as access details.

*** 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.

#1903687

My issue is resolved now. Thank you!