Home › Forums › Front-end Issues › Dynamically Set A Front-End Form Field › Reply To: Dynamically Set A Front-End Form Field
Your acf/pre_save_post filter does not run before the form is submited, it is run after the form is submitted. Once the form is submitted any value you passed to the original page in $_GET is lost. It cannot be used to pre-populate a field.
In addition to this, your filter will not even work as expected. Filters like acf/pre_save_post need to be in your functions.php file or in some other file that is always loaded. Your template file will not be loaded during the form submission.
With that said, if you want to pre-populate a field you need to use an acf/prepare_field filter.
add_fitler('acf/prepare_field/key=field_5dba152669aaf', 'populate_vacancy_applied_for');
function populate_vacancy_applied_for($field) {
// only on front end
if (is_admin()) {
return $field;
}
if (isset($_GET['vacancy'])) {
$field['value'] = $_GET['vacancy'];
}
return $field;
}
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.