Skip Navigation

[Resolved] Validate either mailto or url in custom url field

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to add the URL field as either a URL or mailto field with validation? Or I'd like to offer either option as a "call to action" for content contributors.

Solution:
I believe the validation needs to be done before data is saved, in that case it will needs to be done using custom javascript / jquery code. Our Types fields and WordPress native custom fields does not allow 2 kinds of validation on the same field.

So I recommend you to please use 2 separate fields for this purpose that is the easier approach.

This support ticket is created 7 years, 1 month 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

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

This topic contains 8 replies, has 3 voices.

Last updated by Kacey 7 years ago.

Assisted by: Noman.

Author
Posts
#581264

Is there a way to offer the URL field as either a URL or mailto field with validation? It seems like I can't do both in one field, but I'd like to offer either option as a "call to action" for my content contributors.

#581389

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - there is no such feature available but what you say is the URL field either contain URL value or mailto value - correct?

#581578

yes - I'd like my users to be able to enter either a mailto: link or a url, and have either one validate. Any suggestions for how to go about this?

#581601

Minesh
Supporter

Languages: English (English )

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

Well - is this for any post type with custom post field or with user custom field?

And where user will input the content using wp-admin or using CRED form?

If you will tell me exact flow it will help me to guide you in right direction.

#582554

It is for a custom field on a post, not a user field. Some content editors will be using the admin interface but submissions are also being taken through a CRED form.

#582602

Minesh
Supporter

Languages: English (English )

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

Well - I suggest, for CRED form, you can use the CRED hook: cred_form_validate and validate the user input.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

You can validate URL using following:
=> hidden link

You can validate meilto email using follwong:
=> hidden link

#584655

It seems like I can't use both validation options in one field. Here's a more simple description of what I'm trying to accomplish:
I'd like to have ONE field in which content editors can either put an external URL or an email address. Is it possible to identify which of these two content types are being entered and then validate?

#584790

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Allison,

I am going to take over this ticket since Minesh is on vacations, I hope that’s ok. After looking into your request I believe the validation needs to be done before data is saved, in that case it will needs to be done using custom javascript / jquery code. Our Types fields and WordPress native custom fields does not allow 2 kinds of validation on the same field.

So I recommend you to please use 2 separate fields for this purpose that is the easier approach.

Other than that falls into Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/). So we recommend to contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

Thank you

#586888

THank you