Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of how to use Caldera Forms Connected Forms hooks to send an email with a link to continue the form sequence. See - https://calderaforms.com/doc/connected-caldera-forms-hooks/
/**
* Send an email to the person who has filled out the first form in a Caldera Forms connected forms sequence with a link to continue.
*/
add_action( 'cf_form_connector_sequence_started', function ( $form_id, $entry_id, $user_id ) {
//change this to the URL that your form is on
$url = 'https://hiroy.club/sign-up';
//add cfcf-id query var with user identifier
$url = add_query_arg( 'cfcf-id', $user_id, $url );
//Change this to the ID of the field with the email address - MUST be in frist form of sequence
$email_field = 'fld_7474165';
//Change this to the ID of the frield with name -- Must be in first form of sequence
$name_field = 'fld_9697545';
//Get all submission data
$data = Caldera_Forms::get_submission_data( $form_id );
//get email and name
$to = $data[ $email_field ];
$name = $data[ $name_field ];
//Change your email message
$subject = 'Thanks for starting the application form';
$body = 'Hi ' . $name . '. You can go back to this form at any time. Just use this <a href="' . $url . '">link</a>';
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
wp_mail( $to, $subject, $body, $headers );
}, 10, 3 );
/**
* Change which Caldera Forms connected form sequence data is loaded based on a query variable
*/
add_filter( 'cf_form_connector_position_data', function ( $data ) {
//check for query var
if ( isset( $_GET[ 'cfcf-id' ] ) ) {
//Could be a user ID
if ( is_numeric( $_GET[ 'cfcf-id' ] ) ) {
//is this the right user?
if ( get_current_user_id() === $_GET[ 'cfcf-id' ] ) {
//nope, make them log back in
auth_redirect();
}
//see if we have progress in user meta
$_data = get_user_meta( get_current_user_id(), CF_FORM_CON_SLUG, true );
//yes we do, so use it.
if ( ! empty( $_data ) ) {
return $_data;
}
} //could be cookie ID
elseif ( is_string( $_GET[ 'cfcf-id' ] ) ) {
//see if we have tracked data
$_data = get_option( 'cfcfrm_' . $_GET[ 'cfcf-id' ], array() );
//yes we do, so use it.
if ( ! empty( $_data ) ) {
return $_data;
}
}
}
return $data;
}, 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.