GFAPI::update_entry_field [RESOLVED]

I am trying to populate a text field of a form (form ID is 1) with a URL link using GFAPI:: update_entry_field. The ID of the hidden field is 115 and the link needs to include the entry of another text field (ID 90) as a filter for a data table. I am using the following code but it is not populating anything in the field with ID 115. I have obviously got the syntax wrong somewhere Can anyone help me please? Thanks

add_action( 'gform_after_submission_1', 'combine_view_name', 10, 2 );

function combine_view_name( $entry, $form_id ) {
    $uniquev_field = '90';  // Change this to the ID of the Unique Field
    $view_name = "115";   // Change this is the Id of the hidden single line text field that will hold the combined values
    $view_entry[$view_name] = "https://www.mywebsite.com/mypage/?wdt_column_filter[0]=". $entry[$uniquev_field];
   GFAPI::update_entry_field( $entry, $view_name, $view_entry );
}

In GFAPI::update_entry_field the first parameter should be an entry ID, not the $entry. gform_after_submission has access to the $entry, so you need to get the entry ID to use that. Like this:

GFAPI::update_entry_field( rgar( $entry, 'id' ), $view_name, $view_entry );

There are lots of other ways to get the entry ID, but that is what you need to do: provide and $entry ID to the update_entry_field function.

Chris
Thanks for this. That has helped my understanding of what is required for that function. I have amended my snippet (see below) but this is not populating anything in field 115? Can you see any reasons why it is not updating? Prior to this I was using “GFAPI::update_entry($entry)” and it has all worked OK. So it seems that there is something in my introduction of “GFAPI::update_entry_field ( rgar($entry,‘id’), $view_name, $view_name )” that is causing a problem such that the link is not now being populated.

add_action( 'gform_after_submission_1', 'combine_view_name', 10, 2 );

function combine_view_name( $entry, $form_id ) {
	$unique_field = '90';  // Change this to the ID of the Unique Field
    $view_name = "115";   // Change this is the Id of the hidden single line text field that will hold the combined values
    $view_entry[$view_name] = "mywebsite/mypage/?wdt_column_filter[0]=". $entry[$unique_field];
    GFAPI::update_entry_field( rgar( $entry,'id' ), $view_name, $view_entry );
}

I recommend enabling Gravity Forms logging, and adding some custom logging statements to your code to see what is going on.

Enable logging:

Then add some custom logging statements to your code:

You could try something like this:

add_action( 'gform_after_submission_1', 'combine_view_name', 10, 2 );
function combine_view_name( $entry, $form_id ) {
	// log the entry
	GFCommon::log_debug( __METHOD__ . '(): The Entry => ' . print_r( $entry, true ) );
	$unique_field = '90';  // Change this to the ID of the Unique Field
    $view_name = "115";   // Change this is the Id of the hidden single line text field that will hold the combined values
    $view_entry[$view_name] = "mywebsite/mypage/?wdt_column_filter[0]=". $entry[$unique_field];
	// log $view_entry
	GFCommon::log_debug( __METHOD__ . '(): My View Entry => ' . print_r( $$view_entry, true ) );
    $result = GFAPI::update_entry_field( rgar( $entry,'id' ), $view_name, $view_entry );
	// log the result of the update 
	GFCommon::log_debug( __METHOD__ . "(): Result of update_entry_field: {$result}." );
}

Send a link to your Gravity Forms Core log file if you’re not able to figure it out after adding the logging and testing the submission. Thank you.

Chris

Thanks
I’ve tried that
Cant make head or tail of the logs.
How do I send you a link?
Or can I just send you pdf copy to view?
Thanks

Chris

HI Chris

Here is the log
I don’t understand any of it I’m afraid

If you can shed any light I would be most grateful.

Many thanks

Chris

(Attachment gravityforms_e373908c4942ae8464f305c8ae67c9043c47eb9f.pdf is missing)

Can you send a link to the log file on your site? If you go to Forms → Settings → Logging, hover over the Gravity Forms Core log, and copy and paste the link here. (The PDF did not come through)

Hi Chris

Thanks

Gravity Forms Core

https://casswizard.com/brokerltd/wp-content/uploads/sites/5/gravity_forms/logs/gravityforms_e373908c4942ae8464f305c8ae67c9043c47eb9f.txt

Many thanks

Chris

Hi Chris. Looks like I had a typo in my code, in this line:

GFCommon::log_debug( __METHOD__ . '(): My View Entry => ' . print_r( $$view_entry, true ) );

Can you remove the double $$ and make that $view_entry instead, then test again? Thank you.

Hi Chris

Done.

I deleted the old log and just added another entry.

New link

https://casswizard.com/brokerltd/wp-content/uploads/sites/5/gravity_forms/logs/gravityforms_e373908c4942ae8464f305c8ae67c9043c47eb9f.txt://casswizard.com/brokerltd/wp-content/uploads/sites/5/gravity_forms/logs/gravityforms_e373908c4942ae8464f305c8ae67c9043c47eb9f.txt

Chris

Thank you. Sorry about this. This is the relevant portion of that logging:

2022-02-08 18:53:56.161818 - DEBUG --> combine_view_name(): My View Entry => Array
(
    [115] => https://casswizard.com/brokerltd/insurer-toba-3/?wdt_column_filter[0]=IT00242
)
 
2022-02-08 18:53:56.172187 - DEBUG --> GFFormsModel::update_entry_field_value(): bailing. value is an array. 
2022-02-08 18:53:56.172283 - DEBUG --> combine_view_name(): Result of update_entry_field: . 

You are trying to store an array $view_entry in a field value. That won’t work and the logging tells you that. What are you trying to get stored into that field in the entry? Do you need to store only $view_name there?

Looking at the documentation:

public static function update_entry_field( $entry_id, $input_id, $value ) {}

You should be sending an entry ID, input ID, and the value you want to store in that field (input ID).

So it should be something like:

$result = GFAPI::update_entry_field( rgar( $entry,'id' ), $view_name, $view_entry );

But that would only work if $view_entry is a string, like this:

$view_entry = "mywebsite/mypage/?wdt_column_filter[0]=". $entry[$unique_field];

Why are you making $view_entry an array?

Hi Chris

Thank you.

Good question. The answer is I had copied that from a snippet I found elsewhere.
You are right, it does not need to be an array.
As you may have gathered, I’m not an experienced coder.
I’m navigating my way building this web app and learning loads in the process.

Thank you so very much for your assistance.

Using a combination of Wordpress, Gravity, WPDatatables and a number of other plugins I am really making great progress.

That is very much down to great support from people like yourself.

Thank you so much.

Regards

Chris

Does it work now, with the string being stored as the value?

Hi Chris

Yes it does work.
This enables me to store file links in fields.

Many Thanks again

Chris

Yes it works brilliantly. Not sure if you got my previous email

Many thanks

Chris

Great news! Let us know if you need anything else.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.