Home › Forums › General Issues › Select Dropdown Inside Repeater With Mailto and Tel based on Selection
Trying to setup inside my Repeater a way for me to select either EMAIL ADDRESS or PHONE NUMBER.
– if i select EMAIL ADDRESS, it would populate the ‘mailto:’ before the email subfield where i’d enter the email
– if i select PHONE NUMBER, it would populate the ‘tel:’ before the phone number that’s entered into the field
is there a way to do this with an if else using one field for the email/phone
if i entered in the subfield: [email protected] or 333-333-4444, it could then know based on the dropdown selection whether to add mailto: or tel: before that field?
Do you need this to change on the backend or frontend? For the backend, you can change the prefix of a field using a filter. On the frontend, a regex to the field can determine whether to use mailto: or tel:.
Thanks for the response — see below with image and php that helps explain
IMAGE EXPLAINATION:
https://pasteboard.co/5fFEy9KEfp0o.jpg
PHP CODE:
PHP CODE HERE: https://onlinephp.io/c/ea1db
-user goes to WP Page
->Adds Image, Title, etc
-Select Dropdown – choice of PHONE or EMAIL
If user Selects PHONE, it populates tel: before the subfield they enter of a phone number so it makes it a link
If user Selects EMAIL, it populates mailto: before the subfield they enter of a phone number so it makes it a link
if (get_field('select_field_name') == 'EMAIL ADDRESS') {
echo 'mailto:';
} else {
echo 'tel:';
}
See image and php code below but essentially:
-user goes to WP Page
-Adds Image, Title, etc
-Select Dropdown – choice of PHONE or EMAIL
If user Selects PHONE, it populates tel: before the subfield they enter of a phone number so it makes it a link
If user Selects EMAIL, it populates mailto: before the subfield they enter of a phone number so it makes it a link
Image Explanation: https://pasteboard.co/5fFEy9KEfp0o.jpg
Code Sandbox: : https://onlinephp.io/c/ea1db
in the php code – its in the div “phoneemail-selection” towards bottom where id imagine the IF / ELSE statement would go:
See image and php code below but essentially:
-user goes to WP Page
-Adds Image, Title, etc
-Select Dropdown – choice of PHONE or EMAIL
If user Selects PHONE, it populates tel: before the subfield they enter of a phone number so it makes it a link
If user Selects EMAIL, it populates mailto: before the subfield they enter of a phone number so it makes it a link
————
Image Explanation: https://pasteboard.co/5fFEy9KEfp0o.jpg
Code Sandbox: : https://onlinephp.io/c/ea1db
in the php code – its in the div “phoneemail-selection” towards bottom where id imagine the IF / ELSE statement would go:
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.