Can anyone help/have some ideas on how to prepopulate gravityforms fields based on users latest entry of the same form. I've users, who will "register" to an event every year and fill the same form, so it would be nice to have the same fields already filled and if the client wants, they can refill some of the changed fields themselves.
So far I've found some info from gravityforms docs myself, but this code seems only to be prepopulating only one field? Still haven't gotten it to work. The code ->
add_filter( 'gform_field_value_previous_value', 'populate_previous_value', 10, 2 );
function populate_previous_value( $value, $field ) {
$entries = GFAPI::get_entries(
$field->formId,
array(
'field_filters' => array(
array(
'key' => 'created_by',
'value' => get_current_user_id(),
),
),
),
array(),
array( 'page_size' => 1 )
);
return rgars( $entries, '0/' . $field->id );
}
I assume, the value between the rgars apostrophes aka the field id needs to be filled?
If anyone else is wondering/struggling to solve this issue - I've come to the realization that the best and easiest way to pre-populate fields values based on logged in user is through gravity forms merge tags.
Best way to use merge tags based on logged in user is next:
{user:[meta_tag}
You can use all the meta fields available, also the billing_address and billing_postcode and so on, as long as you include 'user:' before.
So the fields get populated based on logged in users meta fields. The merge tags need to be placed to form field->advanced->under default value.
For example if you need logged in users first name and last name to be populated you would add {user:first_name} to the first name default value field and {user:last_name} to the last name value field.