I'm having trouble getting the Gravity Forms entry ID after submitting the for in the 'gform_pre_send_email' function.
In the GF log the Entry ID is visible:
DEBUG --> GFFormsModel::save_entry(): Saving entry.
DEBUG --> GFFormsModel::save_entry(): **Entry record created in the database. ID: 95.**
DEBUG --> GFFormsModel::save_entry(): Saving entry fields.
After setting $entry as global within the function, rgar( $entry, 'id' ) returns empty as does var_dump( $entry ). Same goes for the $form array. The $_POST array doesn't yet contain the entry ID.
Also the API returns empty: GFAPI::get_entry( $entry_id ).
$wpdb->insert_id does provide a number, but it isn't the correct ID of the entry.
I've tried many options, read many posts, finished Google. It's seems such a simple quest but i'm missing out in how to handle this.
Used code:
add_filter( 'gform_pre_send_email', 'before_email' );
function before_email( $email ) {
global $entry;
$entryid = rgar( $entry, 'id' );
//DEBUGGING
echo '<br><br>POST:<br>';
var_dump( $_POST );
echo '<br><br>Entry:<br>';
var_dump( $entry );
echo '<br><br>';
$pattern = "PAYMENTLINK";
$replacement = "<a href='https://******.***/checkout/?add-to-cart=44&entryid=$entryid' target='_blank'>https://******.***/pay</a>";
$email['message'] = str_replace($pattern, $replacement, $email['message']);
return $email;
}
How to i get the entry ID of the just submitted form? Thanks
Oke, many hours spend, solution found. Stupid to over see this..
Function with 1 argument:
add_filter( 'gform_pre_send_email', 'before_email' );
function before_email( $email ) {
Function with 4 arguments (Note the ,10 ,4 in the add_filter):
add_filter( 'gform_pre_send_email', 'before_email' , 10, 4 );
function before_email( $email, $message_format, $notification, $entry) {