Skip to content
Hookturn Hookturn Docs

How to pre-fill form field values

There are two ways to pre-fill form field values: via the values form arg (best for static data known at render time) or via the af/field/prefill_value filter (best when the value needs to be computed or conditional).

When rendering the form with advanced_form(), pass a values array keyed by field name:

advanced_form( 'YOUR_FORM_KEY_HERE', [
'values' => [
'first_name' => 'John',
'last_name' => 'Doe',
],
] );

The values arg works with the function only — the [advanced_form ...] shortcode doesn’t currently support it.

For programmatic / conditional pre-fills, hook the filter:

add_filter( 'af/field/prefill_value', function ( $value, $field, $form, $args ) {
// Only run for the target form.
if ( $form['key'] !== 'YOUR_FORM_KEY_HERE' ) {
return $value;
}
if ( $field['name'] === 'first_name' ) {
return 'John';
}
if ( $field['name'] === 'last_name' ) {
return 'Doe';
}
return $value;
}, 10, 4 );

The filter fires per-field on render, so you can pull values from anywhere — wp_get_current_user(), a related post, an API call, the URL — and return them per $field['name'] (or $field['key'] if you prefer keys).