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:
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.
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)
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?
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.