简体   繁体   English

重力形式 $field_values 不起作用

[英]Gravity forms $field_values not working

I am running the most curent version of WP and Gravity forms.我正在运行 WP 和 Gravity 形式的最新版本。 I'm trying to call the form through a template file and pass through a few things like so:我正在尝试通过模板文件调用表单并通过一些类似的事情:

gravity_form(2, $display_title=false, $display_description=true,
 $field_values, $ajax=true);

I'm calling the $field_values like so:我像这样调用$field_values

$field_values = array("my" => "FOO", "your" => "BAR",);

They are simple not populating into gravity forms.它们很简单,不会以重力形式出现。 Any ideas?有任何想法吗?

Make sure to click on the field and then click on the advanced tab and check mark the prepopulate field checkbox.确保单击该字段,然后单击高级选项卡并选中预填充字段复选框。 This will drop down a text box in which you can specify a parameter name.这将下拉一个文本框,您可以在其中指定参数名称。

Ok, lets say that your form ID is 7, let me give you a step-by-step answer:好的,假设您的表单 ID 为 7,让我逐步回答您:

  1. Create your form创建您的表单
  2. Go to advanced进入高级
  3. Check "Allow field to be populated dynamically"选中“允许动态填充字段”
  4. Give it a name, eg.: my_name给它一个名字,例如: my_name
  5. gravity_form(7, false, false, false, array('my_name'=>'whatever you want to autofill'), false);

Now if you go to that form you will see that the field which had the name my_name has the value whatever you want to autofill .现在,如果您转到该表单,您将看到名称为my_name的字段具有whatever you want to autofill值。

Hope this helped, bye bye.希望这有帮助,再见。

This documentation gives some helpful advice on populating fields:本文档提供了一些有关填充字段的有用建议:

gravityhelp.com/documentation/page/Allow_field_to_be_populated_dynamically gravityhelp.com/documentation/page/Allow_field_to_be_populated_dynamically

and here is an example of how I populate fields using a hook:这是我如何使用钩子填充字段的示例:

add_filter("gform_field_value_yourparametername", "populate_yourparametername");

function populate_yourparametername($value){
    global $post; 
    $value = get_post_meta( $post->ID,'metakeyname',true);
   return $value;

}

In order for this to work, you must check the box in the advanced tab of the form item in your Gravity Form that allows the field to be populated dynamically.为了使其工作,您必须选中重力表单中表单项的高级选项卡中的框,该框允许动态填充该字段。 Then you need to fill in the input below with 'youparametername'.然后你需要用'youparametername'填写下面的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM