Created
January 7, 2019 05:55
-
-
Save yuliyang/bbc182239eacc6b0330c7e6878ef63e0 to your computer and use it in GitHub Desktop.
[Gravity Form] Repeater field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// change "3" to your form ID | |
add_filter( 'gform_form_post_get_meta_3', 'add_my_field' ); | |
function add_my_field( $form ) { | |
$name = GF_Fields::create( array( | |
'type' => 'text', | |
'id' => 1005, | |
'formId' => $form['id'], | |
'label' => '姓名', | |
) ); | |
$email = GF_Fields::create( array( | |
'type' => 'email', | |
'id' => 1002, | |
'formId' => $form['id'], | |
'label' => '電子郵件', | |
) ); | |
$phone = GF_Fields::create( array( | |
'type' => 'phone', | |
'id' => 1003, | |
'formId' => $form['id'], | |
'label' => '電話', | |
) ); | |
$line = GF_Fields::create( array( | |
'type' => 'text', | |
'id' => 1004, | |
'formId' => $form['id'], | |
'label' => 'Line ID', | |
) ); | |
$team = GF_Fields::create( array( | |
'type' => 'repeater', | |
'description' => '', | |
'id' => 1000, | |
'formId' => $form['id'], | |
'label' => '同行朋友資訊', | |
'addButtonText' => '新增同行朋友', // Optional | |
'removeButtonText' => '刪除同行朋友', // Optional | |
'maxItems' => 5, // Optional | |
'fields' => array( $name, $email, $phone, $line ), // Add the fields here. | |
) ); | |
$form['fields'][] = $team; | |
return $form; | |
} | |
add_filter( 'gform_form_update_meta_3', 'remove_my_field', 10, 3 ); | |
function remove_my_field( $form_meta, $form_id, $meta_name ) { | |
if ( $meta_name == 'display_meta' ) { | |
$form_meta['fields'] = wp_list_filter( $form_meta['fields'], array( 'id' => 1000 ), 'NOT' ); | |
} | |
return $form_meta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment