简体   繁体   English

在重力形式中设置“名称”字段的默认值

[英]Setting default value of Name field in Gravity Forms

In Gravity Forms you can set the default value of a field by using code like: 在重力形式中,可以使用以下代码来设置字段的默认值:

$field->defaultValue = 'My default value';

this is mentioned in documentation here: https://docs.gravityforms.com/field-object/ 此处的文档中提到了这一点: https : //docs.gravityforms.com/field-object/

However this doesn't work for the Name field as this is a multi-input field as it contains a first and last name. 但是,这对于“名称”字段不起作用,因为这是一个多输入字段,因为它包含名字和姓氏。 How do I set the default value of the name field in Gravity Forms? 如何在重力表格中设置名称字段的默认值?

As you mentioned, the Name field is a multi-input field. 如前所述,“名称”字段是一个多输入字段。 You must interact with the desired input on a multi-input field. 您必须在多输入字段上与所需的输入进行交互。 For example, to set the first name, you would do something like this: 例如,要设置名字,您可以执行以下操作:

$field->inputs[2]['defaultValue'] = 'Dave';

Here is the full contents of the inputs field property as JSON: 这是inputs字段属性的完整内容, inputs为JSON:

[{ "id": "9.2", "label": "Prefix", "name": "", "choices": [{ "text": "Mr.", "value": "Mr.", "isSelected": false, "price": "" }, { "text": "Mrs.", "value": "Mrs.", "isSelected": false, "price": "" }, { "text": "Miss", "value": "Miss", "isSelected": false, "price": "" }, { "text": "Ms.", "value": "Ms.", "isSelected": false, "price": "" }, { "text": "Dr.", "value": "Dr.", "isSelected": false, "price": "" }, { "text": "Prof.", "value": "Prof.", "isSelected": false, "price": "" }, { "text": "Rev.", "value": "Rev.", "isSelected": false, "price": "" }], "isHidden": true, "inputType": "radio", "defaultValue": "Mr." }, { "id": "9.3", "label": "First", "name": "", "defaultValue": "David" }, { "id": "9.4", "label": "Middle", "name": "", "isHidden": true, "defaultValue": "Stover" }, { "id": "9.6", "label": "Last", "name": "", "defaultValue": "Smith" }, { "id": "9.8", "label": "Suffix", "name": "", "isHidden": true, "defaultValue": "Jr." }]

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

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