Skip to main content

GravityKit\GravityMigrate\Schema\GfCompositeInputs

Builds the full input set a Gravity Forms composite field expects.

Gravity Forms looks up a composite field's inputs by fixed id and does not check whether they exist: GF_Field_Name reads the prefix input at .2 whether or not a prefix is shown, and GF_Field_Time reads .1 and .2 for its hour and minute labels. Supply only the inputs a form actually uses and those lookups return null: every render emits PHP notices and the sub-labels fall back to defaults that can no longer be edited.

Gravity Forms' own editor always creates the complete set and marks the unused entries hidden (GetAdvancedNameFieldInputs in js.php), which is what these build.

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:24

Details​

  • Kind: class
  • Namespace: GravityKit\GravityMigrate\Schema

Methods​

MethodDescription
address()The six inputs a Gravity Forms address stores its parts in.
visible_name_parts()Which parts of a name field are actually shown.
name()Builds the five inputs a name field expects.
date()The inputs a Gravity Forms date field reads when it is shown as separate boxes.
with_placeholders()Puts a placeholder on the inputs named by id suffix.
time()Builds the three inputs a time field expects.
password()The two inputs a Gravity Forms password field carries.
labelled()Puts the wording on the key Gravity Forms draws.

Method Reference​

address()​

public static function address( int $field_id ): array

The six inputs a Gravity Forms address stores its parts in.

Read off the field's own renderer, which addresses them positionally: .1 street, .2 line two, .3 city, .4 state, .5 zip, .6 country (includes/fields/class-gf-field-address.php:163-177).

Parameters​

NameTypeDefaultDescription
$field_idintGravity Forms field id.

Returns​

  • array

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:39

visible_name_parts()​

public static function visible_name_parts( array $field ): array

Which parts of a name field are actually shown.

Gravity Forms' nameFormat says whether a name is one box or several, not which several. "advanced" means multi-part, and each part is shown or hidden by its own input's isHidden, which is what the field's own rendering reads (if ( $is_admin || ! rgar( $middle_input, 'isHidden' ) ), class-gf-field-name.php:296). Every ordinary first-and-last name is "advanced" with the prefix, middle and suffix hidden, so reading the format alone and treating "advanced" as all five parts puts boxes on the far side that nobody asked for.

A field carrying no inputs at all is read as first and last, Gravity Forms' own default.

Parameters​

NameTypeDefaultDescription
$fieldarrayGravity Forms name field.

Returns​

  • string[] — The parts shown, in the order Gravity Forms keeps them.

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:80

name()​

public static function name( int $field_id, array $visible=[ 'first', 'last' ], array $labels=[] ): array

Builds the five inputs a name field expects.

Parameters​

NameTypeDefaultDescription
$field_idintGravity Forms field id.
$visiblestring[][ 'first', 'last' ]Which parts are shown: prefix, first, middle, last, suffix.
$labelsarray[]Optional part => label overrides.

Returns​

  • array

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:114

date()​

public static function date( int $field_id, array $placeholders=[] ): array

The inputs a Gravity Forms date field reads when it is shown as separate boxes.

Gravity Forms looks the three up by fixed id, month first, then day, then year (class-gf-field-date.php:230), and reads a placeholder off each of them. A date shown as one picker has no boxes to put wording in, so it is given none.

Parameters​

NameTypeDefaultDescription
$field_idintGravity Forms field id.
$placeholdersarray[]Placeholders keyed month, day, year.

Returns​

  • array

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:163

with_placeholders()​

public static function with_placeholders( array $inputs, array $placeholders ): array

Puts a placeholder on the inputs named by id suffix.

A composite field keeps its wording per part rather than one for the whole field.

Parameters​

NameTypeDefaultDescription
$inputsarrayInputs.
$placeholdersarrayPlaceholders keyed by id suffix.

Returns​

  • array

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:203

time()​

public static function time( int $field_id, bool $is_24_hour=false ): array

Builds the three inputs a time field expects.

The AM/PM input exists on a 24 hour field too, hidden, because Gravity Forms reads it when the format is switched back.

Parameters​

NameTypeDefaultDescription
$field_idintGravity Forms field id.
$is_24_hourboolfalseWhether the field uses a 24 hour clock.

Returns​

  • array

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:231

password()​

public static function password( int $field_id, bool $confirm, array $labels=[], array $placeholders=[] ): array

The two inputs a Gravity Forms password field carries.

Gravity Forms decides whether to draw the Confirm Password box from the SECOND input, and it reads an absent one as ENABLED: isset( $confirm_input['isHidden'] ) ? ! $confirm_input['isHidden'] : true (class-gf-field-password.php:496-503). A field imported with no inputs therefore arrives asking the visitor to type their password twice, whatever the source form drew -- and on Ninja Forms, whose password and passwordconfirm are separate field types, two source boxes become four, with the two confirmations blank and mandatory.

The first input is NOT numbered. GF_Field_Password reaches for it as GFFormsModel::get_input( $this, $this->id . '' ) -- the bare field id -- and only the confirmation carries a suffix (class-gf-field-password.php:280-281). Writing .1 makes the lookup miss, because get_input() compares $input['id'] == $id numerically (forms_model.php:6865-6875), and the box then renders with no placeholder at all.

Parameters​

NameTypeDefaultDescription
$field_idintGravity Forms field id.
$confirmboolWhether the source form asked for the confirmation box.
$labelsstring[][]Optional enter and confirm wording.
$placeholdersstring[][]Optional enter and confirm prompts.

Returns​

  • array

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:282

labelled()​

public static function labelled( array $input, string $stock, string $authored ): array

Puts the wording on the key Gravity Forms draws.

Every composite renderer draws customLabel when it is not empty and its own stock wording otherwise -- GF_Field_Name (class-gf-field-name.php:291-295), GF_Field_Address (:219-229), GF_Field_Password (:283-286), GF_Field_Time (:321-331), GF_Field_CreditCard (:329-442) -- and none of them reads label. So an author's wording written to label shows in the validation message, where GF_Field::get_input_property() falls back to it (class-gf-field.php:1194-1196), and nowhere else. label keeps the stock wording, as the editor writes it.

Parameters​

NameTypeDefaultDescription
$inputarrayThe input, without either label key.
$stockstringGravity Forms' own wording for the part.
$authoredstringWhat the source form's author wrote over it; '' for nothing.

Returns​

  • array

Since: %ver%

Source: src/Schema/GfCompositeInputs.php:329