Home › Forums › General Issues › Prefilling fields not visible to user
Hi Guys,
Forgive me if this is an obvious question but a complete beginner in the world of coding.
Is there anyway I can prefill part of the form which the user can’t see but it does it automatically. I have a few ideas for this for example:
URL – prefill https://
Phone number – prefill tel:
Instagram username: prefill https://Instagram.com/ (so all they need to input is there username).
Will appreciate any help i can get in this thanks.
Thanks John, I had wondered if this was the answer to my question in research. So thanks for confirming.
Hi John, I am adding the following to my theme functions file but not having much luck.
function my_acf_prepare_field( $field ) {
// Lock-in the value "https://instagram.com/".
if( $field['value'] === 'https://instagram.com/' ) {
$field['readonly'] = true;
};
return $field;
add_filter('acf/prepare_field/name=instagram', 'my_acf_prepare_field');
}
Is it because I am using the ACF Frontend plugin?
Thanks in advance
You need to put add_filter() outside of the function
function my_acf_prepare_field( $field ) {
// Lock-in the value "https://instagram.com/".
if( $field['value'] === 'https://instagram.com/' ) {
$field['readonly'] = true;
};
return $field;
}
add_filter('acf/prepare_field/name=instagram', 'my_acf_prepare_field');
Thanks for confirming John, still no luck for me unfortunately.
I just noticed that you are no setting the value, only trying to make it readonly if it’s already set to a specific value. Maybe I’m confused about what you’re trying to do.
Perhaps, let me try and share some more insight, I have a front end form which people fill in to customise a profile on the front end too. I would like the https://instagram.com/ to be filled in the field before they even touch the form but not visible. So I can then label the field “instagram username” when they put there username in it creates the value https://instagram.com/username for a button to be clicked and redirected to their instagram profile.
I would not bother with a field for the Instagram URL. I would just have a “intagram user name” field and then if it’s filled in then output the url in code, something like this:
if (get_field('intagram_user_name')) {
?><a href="https://instagram.com/<?php
the_field('intagram_user_name'); ?>" target="_blank>Instagram</a><?php
}
Storing the actual URL to instagram for every user seems like a waste of DB space.
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.