-
-
Save MDRietveld/1253a5c0fc1ea43d540235e4a7f36b92 to your computer and use it in GitHub Desktop.
This file contains 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 | |
class GF_Field_Contact extends GF_Field { | |
public $type = 'contact'; | |
function get_form_editor_field_settings() { | |
return array( | |
'conditional_logic_field_setting', | |
'prepopulate_field_setting', | |
'error_message_setting', | |
'label_setting', | |
'label_placement_setting', | |
'admin_label_setting', | |
'size_setting', | |
'rules_setting', | |
'visibility_setting', | |
'duplicate_setting', | |
'default_value_setting', | |
'placeholder_setting', | |
'description_setting', | |
'contact_setting', | |
// 'my_standard_settings', | |
'css_class_setting', | |
); | |
} | |
public function is_conditional_logic_supported() { | |
return true; | |
} | |
public function get_form_editor_field_title() { | |
return esc_attr__('Contact', 'gravityforms'); | |
} | |
public function get_form_editor_button() { | |
return array( | |
'group' => 'advanced_fields', | |
'text' => $this->get_form_editor_field_title() | |
); | |
} | |
public function get_field_label_class(){ | |
return 'gfield_label gfield_label--left gfield_label_before_complex'; | |
} | |
public function get_form_editor_inline_script_on_page_render() { | |
// set the default field label for the field | |
return " | |
function SetDefaultValues_contact(field) { | |
field.label = " . json_encode( esc_html__( 'Contact', 'gravityforms' ) ) . "; | |
field.inputs = [ | |
new Input(field.id + 0.1, " . json_encode( gf_apply_filters( array( 'gform_contact_name', rgget( 'id' ) ) , esc_html__( 'Name', 'gravityforms' ), rgget( 'id' ) ) ) . " ), | |
new Input(field.id + 0.2, " . json_encode( gf_apply_filters( array( 'gform_contact_phone', rgget( 'id' ) ) , esc_html__( 'Phone', 'gravityforms' ), rgget( 'id' ) ) ) . " ), | |
new Input(field.id + 0.3, " . json_encode( gf_apply_filters( array( 'gform_contact_email', rgget( 'id' ) ) , esc_html__( 'Email', 'gravityforms' ), rgget( 'id' ) ) ) . " ), | |
]; | |
}"; | |
} | |
// public function validate( $value, $form ) { } | |
// Override this method to save the entry value in a custom format. | |
// public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) {} | |
public function get_field_input( $form, $value = '', $entry = null ) { | |
$is_entry_detail = $this->is_entry_detail(); | |
$is_form_editor = $this->is_form_editor(); | |
$is_admin = $is_entry_detail || $is_form_editor; | |
$form_id = absint( $form['id'] ); | |
$id = intval( $this->id ); | |
$field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_$id" : 'input_' . $form_id . "_$id"; | |
$form_id = ( $is_entry_detail || $is_form_editor ) && empty( $form_id ) ? rgget( 'id' ) : $form_id; | |
$disabled_text = $is_form_editor ? "disabled='disabled'" : ''; | |
$class_suffix = $is_entry_detail ? '_admin' : ''; | |
$required_attribute = $this->isRequired ? 'aria-required="true"' : ''; | |
$form_sub_label_placement = rgar( $form, 'subLabelPlacement' ); | |
$field_sub_label_placement = $this->subLabelPlacement; | |
$is_sub_label_above = $field_sub_label_placement == 'above' || ( empty( $field_sub_label_placement ) && $form_sub_label_placement == 'above' ); | |
$sub_label_class_attribute = $field_sub_label_placement == 'hidden_label' ? "class='hidden_sub_label screen-reader-text'" : ''; | |
$name_value = ''; | |
$phone_value = ''; | |
$email_value = ''; | |
if ( is_array( $value ) ) { | |
$name_value = esc_attr( rgget( $this->id . '.1', $value ) ); | |
$phone_value = esc_attr( rgget( $this->id . '.2', $value ) ); | |
$email_value = esc_attr( rgget( $this->id . '.3', $value ) ); | |
} | |
$contact_name_field_input = GFFormsModel::get_input( $this, $this->id . '.1' ); | |
$contact_phone_field_input = GFFormsModel::get_input( $this, $this->id . '.2' ); | |
$contact_email_field_input = GFFormsModel::get_input( $this, $this->id . '.3' ); | |
$name_placeholder_attribute = GFCommon::get_input_placeholder_attribute( $contact_name_field_input ); | |
$phone_placeholder_attribute = GFCommon::get_input_placeholder_attribute( $contact_phone_field_input ); | |
$email_placeholder_attribute = GFCommon::get_input_placeholder_attribute( $contact_email_field_input ); | |
$contact_name_sub_label = rgar( $contact_name_field_input, 'customLabel' ) != '' ? $contact_name_field_input['customLabel'] : esc_html__( 'Name', 'gravityforms' ); | |
$contact_name_sub_label = gf_apply_filters( array( 'gform_contact_name', $form_id, $this->id ), $contact_name_sub_label, $form_id ); | |
$contact_phone_sub_label = rgar( $contact_phone_field_input, 'customLabel' ) != '' ? $contact_phone_field_input['customLabel'] : esc_html__( 'Phone', 'gravityforms' ); | |
$contact_phone_sub_label = gf_apply_filters( array( 'gform_contact_phone', $form_id, $this->id ), $contact_phone_sub_label, $form_id ); | |
$contact_email_sub_label = rgar( $contact_email_field_input, 'customLabel' ) != '' ? $contact_email_field_input['customLabel'] : esc_html__( 'Email', 'gravityforms' ); | |
$contact_email_sub_label = gf_apply_filters( array( 'gform_contact_email', $form_id, $this->id ), $contact_email_sub_label, $form_id ); | |
$tabindex = $this->get_tabindex(); | |
$name = "<span class='ginput_full{$class_suffix} contact_line' id='{$field_id}_1_container'> | |
<label for='{$field_id}_1' id='{$field_id}_1_label' {$sub_label_class_attribute}>{$contact_name_sub_label}</label> | |
<input type='text' name='input_{$id}.1' id='{$field_id}_1' value='{$name_value}' {$tabindex} {$disabled_text} {$name_placeholder_attribute} {$required_attribute}/> | |
</span>"; | |
$tabindex = $this->get_tabindex(); | |
$phone = "<span class='ginput_full{$class_suffix} contact_line' id='{$field_id}_2_container'> | |
<label for='{$field_id}_2' id='{$field_id}_2_label' {$sub_label_class_attribute}>{$contact_phone_sub_label}</label> | |
<input type='text' name='input_{$id}.2' id='{$field_id}_2' value='{$phone_value}' {$tabindex} {$disabled_text} {$phone_placeholder_attribute} {$required_attribute}/> | |
</span>"; | |
$email = "<span class='ginput_full{$class_suffix} contact_line' id='{$field_id}_3_container'> | |
<label for='{$field_id}_3' id='{$field_id}_3_label' {$sub_label_class_attribute}>{$contact_email_sub_label}</label> | |
<input type='text' name='input_{$id}.3' id='{$field_id}_3' value='{$email_value}' {$tabindex} {$disabled_text} {$email_placeholder_attribute} {$required_attribute}/> | |
</span>"; | |
$css_class = 'has_name has_phone has_email ginput_container_contact'; | |
return "<div class='ginput_complex{$class_suffix} ginput_container {$css_class}' id='$field_id'> | |
{$name}{$phone}{$email} | |
<div class='gf_clear gf_clear_complex'></div> | |
</div>"; | |
// ginput_complex ginput_container has_street has_street2 has_city has_state has_zip has_country ginput_container_address | |
// ginput_complex ginput_container has_name has_phone has_email ginput_container_contact | |
} | |
} | |
GF_Fields::register( new GF_Field_Contact() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment