admin管理员组文章数量:1122846
I will be using the following code from ActiveProspects and what it do is basically pass some hidden values (in this case basically a dynamic url) to the server along with the form fields which we need to capture and store in our DB. Now I am using Gravity Forms with my Wordpress site but I am unable to capture that data.
<script type="text/javascript">
(function() {
var field = 'xxTrustedFormCertUrl';
var provideReferrer = false;
var invertFieldSensitivity = false;
var tf = document.createElement('script');
tf.type = 'text/javascript'; tf.async = true;
tf.src = 'http' + ('https:' == document.location.protocol ? 's' : '') +
'://api.trustedform/trustedform.js?provide_referrer=' + escape(provideReferrer) + '&field=' + escape(field) + '&l='+new Date().getTime()+Math.random() + '&invert_field_sensitivity=' + invertFieldSensitivity;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(tf, s); }
)();
</script>
<noscript>
<img src=".gif" />
</noscript>
The following image shows the hidden data and fields
Now here's a gravity forms help page / which says how to pass dynamic data but I am not into php much so any help will be well appreciated. As per this help I have added the following code in my theme functions.php but I think its hard coded. So can anybody let me know how to capture this hidden field value and store it.
add_filter( 'gform_field_value_xxTrustedFormCertUrl', 'my_custom_population_function' );
function my_custom_population_function( $value ) {
return 'Boom';
}
I will be using the following code from ActiveProspects and what it do is basically pass some hidden values (in this case basically a dynamic url) to the server along with the form fields which we need to capture and store in our DB. Now I am using Gravity Forms with my Wordpress site but I am unable to capture that data.
<script type="text/javascript">
(function() {
var field = 'xxTrustedFormCertUrl';
var provideReferrer = false;
var invertFieldSensitivity = false;
var tf = document.createElement('script');
tf.type = 'text/javascript'; tf.async = true;
tf.src = 'http' + ('https:' == document.location.protocol ? 's' : '') +
'://api.trustedform.com/trustedform.js?provide_referrer=' + escape(provideReferrer) + '&field=' + escape(field) + '&l='+new Date().getTime()+Math.random() + '&invert_field_sensitivity=' + invertFieldSensitivity;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(tf, s); }
)();
</script>
<noscript>
<img src="http://api.trustedform.com/ns.gif" />
</noscript>
The following image shows the hidden data and fields
Now here's a gravity forms help page https://docs.gravityforms.com/using-dynamic-population/ which says how to pass dynamic data but I am not into php much so any help will be well appreciated. As per this help I have added the following code in my theme functions.php but I think its hard coded. So can anybody let me know how to capture this hidden field value and store it.
add_filter( 'gform_field_value_xxTrustedFormCertUrl', 'my_custom_population_function' );
function my_custom_population_function( $value ) {
return 'Boom';
}
Share
Improve this question
edited Jul 8, 2020 at 21:58
Sk Samim
asked Jul 5, 2020 at 1:22
Sk SamimSk Samim
11 bronze badge
3
- Does the script create the xxTrustedFormCertUrl input field or just populate one you've already added to the form? If it's populating one you should be able to get it to write the value straight into a Gravity Forms hidden field, which with have a name something like input_1. In which case you'd want PHP to find the name of the field and inject it into the script, not try and autopopulate the field from a non-Gravity input submitted with the form. – Rup Commented Jul 8, 2020 at 22:56
- But if you did want to use the custom population function I guess you'd just read the value from $_POST. – Rup Commented Jul 8, 2020 at 22:56
- The above javascript creates this xxTrustedFormCertUrl hidden field and its value now I just need to get it into any of the gravity form fields that a create. But it seems I have to write some php code in order to capture this value from this hidden field and save it against that gravity form filed. And the worst part is I am from marketing and know nothing about php. – Sk Samim Commented Jul 10, 2020 at 17:13
1 Answer
Reset to default 1I had exactly this problem, and the only way I found to solve it is by creating another hidden field - one that would be saved by Gravity Forms - and then using TrustedForm's JavaScript callback to update that new hidden field.
First, create a hidden field in your form. You can name it anything you want, just make sure you get its field ID.
Next, add this JavaScript to your page. It needs to be above the TrustedForm script that they give you.
<script type="text/javascript">
function trustedFormCertUrlCallback(certificateUrl) {
document.getElementById("input_8_30").value = certificateUrl;
}
</script>
This will echo the certificate URL into your custom field. You can add multiple lines for multiple fields. If you have two or more forms, you'll need to make sure that each form has its own TrustedFormCertUrl field.
You shouldn't need it theoretically, but if you want to add the callback for the ID, so you can add it, you would do the same as above - add another hidden field, and get its ID - and then add this function to your script (also above the TrustedForm script):
<script type="text/javascript">
function trustedFormCertIdCallback(certificateId) {
document.getElementById("input_8_30").value = certificateId;
}
</script>
That should do it. This question was several years old, so I just hope I could help someone else in the future with the same problem as me.
本文标签: pluginsHow to capture hidden values with Gravity Forms
版权声明:本文标题:plugins - How to capture hidden values with Gravity Forms 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304887a1932394.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论