Skip to content

Instantly share code, notes, and snippets.

@KZeni
Last active September 11, 2020 20:14
Show Gist options
  • Save KZeni/180b2d7378bc6f9fc96da4fa29334709 to your computer and use it in GitHub Desktop.
Save KZeni/180b2d7378bc6f9fc96da4fa29334709 to your computer and use it in GitHub Desktop.
Gravity Forms auto-populate Save and Continue Later email field with the current user's email address Based on https://docs.gravityforms.com/gform_pre_process/#4-use-a-form-field-as-email-for-the-save-and-continue-confirmation via https://www.gravityforms.com/gravity-forms-v1-9-save-continue/#comment-23296. Call via functions.php or include inline.
<?php
// Auto-populate Save and Continue Later email field with the current user's email address (on all forms per `gform_pre_process`. Otherwise `gform_pre_process_2`, etc. can be used for specific forms by specifying the ID at the end of the action name. Based on https://docs.gravityforms.com/gform_pre_process/#4-use-a-form-field-as-email-for-the-save-and-continue-confirmation via https://www.gravityforms.com/gravity-forms-v1-9-save-continue/#comment-23296)
// See https://gist.github.com/KZeni/180b2d7378bc6f9fc96da4fa29334709 for latest snippet
add_action( 'gform_pre_process', function ( $form ) {
if ( rgpost( 'gform_save' ) ) {
global $current_user;
get_currentuserinfo();
$current_user_email = $current_user->user_email;
$resume_email = isset( $_POST['gform_resume_email'] ) ? $_POST['gform_resume_email'] : $current_user_email; // Use the supplied resume email if one was specified; otherwise, use the current user's email address as the fallback.
$_POST['gform_resume_email'] = $resume_email;
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment