Pre-Fill Text Field with Another Field (or Title)
-
EDITED: ISSUE ENDED UP BEING SERVER RELATED. TRIED TO DELETE BUT IT WON’T LET ME. ALL GOOD NOW. THANK YOU!
———-
Hi there,
I am trying to dynamically populate (or pre-fill) a field in my AF form with either the title of the post the form is on or – if that is not possible – with the value from another ACF field.
I’ve tried using the code supplied in documentation with no luck. I also found this code from the forums <which the author marked as working> and decided to try it out. The only items I tweaked were the 2nd add_filter (which I changed to the name of the text field I want to be prefilled) and the 3rd add_filter (which I changed to the key of the text field I want to be prefilled). Unfortunately, I also had no luck with this.
Could it be that I am running into an issue because my form is repeated on individual posts within a custom post type?
Any help you can give is appreciated!
function prefill_form_field( $value, $field, $form, $args ) { $user = wp_get_current_user(); $user = $user -> ID; $field ['value']= $user; //set user to current user return $field; } add_filter( 'af/field/prefill_value', 'prefill_form_field', 10, 4 ); add_filter( 'af/field/prefill_value/name=will_sponsor', 'prefill_form_field', 10, 4 ); add_filter( 'af/field/prefill_value/key=field_5e438ab1a9595', 'prefill_form_field', 10, 4 );
- The topic ‘Pre-Fill Text Field with Another Field (or Title)’ is closed to new replies.