Form specific information

By: Jo Whitehouse | Asked: 06/10/2023
ForumsCategory: General questionsForm specific information
Jo Whitehouse asked 10 months ago

Hey guys :) Happy Saturday! Could someone please tell me how to make this following bit applicable to form with ID of 17 only?

 

Tried a few bits and nothing seems to be working:

 

add_filter( 'frm_api_request_args', 'my_custom_frm_api_request_header_getstock', 10, 2 );
function my_custom_frm_api_request_header_getstock( $arg_array, $args ) {
if ( $args['url'] == 'https://api.xxx.com ) {
$arg_array['headers']['Host'] = 'api.xxx.com';
$arg_array['headers']['Content-type'] = 'application/json';
$arg_array['headers']['Accept'] = 'application/json';
$arg_array['headers']['Accept-Charset'] = 'utf-8';
$arg_array['headers']['Authorization'] = 'Bearer eyJmkdsoiuh....';
}
return $arg_array;
}

 

Thank you so much!

1 Answers
Victor Font answered 10 months ago
It depends on the values of the two parameters: $arg_array, $args. Use a PHP debugger like Kint to stop execution and display the contents of the two parameters. If either has a reference to form id, you can achieve what you want.
Jo Whitehouse replied 10 months ago

I think neither does, do you know how to add it in somehow from globally?

Victor Font replied 10 months ago

I just want to confirm. You used Kint or one of the PHP dump commands and examined the full content of the parameters and you don't recognize any element that refers to form ID. Is that correct?

Victor Font replied 10 months ago

I looked at the source code for FrmAPIAppController.php, which is where the frm_api_request_args filter fires in the private prepare_args method. The same array is passed as both filter arguments. The second parameter is for backward compatibility. The array is an associative array:

$args = array(
'url' => $url,
'headers' => $headers,
'body' => $body,
'method' => $method,
'timeout' => self::$timeout,
);

Based on what I'm seeing without reverse engineering code, form id may be in the body or url. Since this is a private class, it is not accessible to a developer even through polymorphism. The private keyword ensures that the declared property/method can only be accessed within the very class in which it is defined (the advantage of private methods/properties). However, the major drawback of using private (if not used correctly) is that child classes cannot inherit such properties/methods at all.

What this means is that of form id isn't in one of the other argument dimensions, you're out of luck. What you may be able to do is use a WordPress conditional is_page() to execute the function only for the page where the form is embedded.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right