is_form_editor() || $this->is_entry_detail() ) ? "field_{$this->formId}_{$this->id}_creditcard_warning_message" : '';
foreach ( $this->inputs as $input ) {
$input_id = str_replace( $this->id . '.', '', $input['id'] );
$input_value = GFForms::get( $input['id'], $values );
if ( ! empty( $_POST[ 'is_submit_' . $this->formId ] ) && $this->isRequired && in_array( $input_id, $required_inputs_ids ) && empty( $input_value ) ) {
$describedby_attributes[ $input_id ] = "aria-describedby='validation_message_{$this->formId}_{$this->id} {$warning_container_id}'";
} else {
$describedby_attributes[ $input_id ] = empty( $warning_container_id ) ? '' : "aria-describedby='{$warning_container_id}'";
}
}
return $describedby_attributes;
}
public function validate( $value, $form ) {
$card_number = rgpost( 'input_' . $this->id . '_1' );
$expiration_date = rgpost( 'input_' . $this->id . '_2' );
$security_code = rgpost( 'input_' . $this->id . '_3' );
if ( $this->isRequired && ( empty( $card_number ) || empty( $security_code ) || empty( $expiration_date[0] ) || empty( $expiration_date[1] ) ) ) {
$this->failed_validation = true;
$this->validation_message = empty( $this->errorMessage ) ? esc_html__( 'Please enter your credit card information.', 'gravityforms' ) : $this->errorMessage;
} elseif ( ! empty( $card_number ) ) {
$card_type = GFCommon::get_card_type( $card_number );
if ( empty( $security_code ) ) {
$this->failed_validation = true;
$this->validation_message = esc_html__( "Please enter your card's security code.", 'gravityforms' );
} elseif ( ! $card_type ) {
$this->failed_validation = true;
$this->validation_message = esc_html__( 'Invalid credit card number.', 'gravityforms' );
} elseif ( ! $this->is_card_supported( $card_type['slug'] ) ) {
$this->failed_validation = true;
$this->validation_message = $card_type['name'] . ' ' . esc_html__( 'is not supported. Please enter one of the supported credit cards.', 'gravityforms' );
}
}
}
public function is_card_supported( $card_slug ) {
$supported_cards = $this->creditCards;
$default_cards = array( 'amex', 'discover', 'mastercard', 'visa' );
if ( ! empty( $supported_cards ) && in_array( $card_slug, $supported_cards ) ) {
return true;
} elseif ( empty( $supported_cards ) && in_array( $card_slug, $default_cards ) ) {
return true;
}
return false;
}
public function get_value_submission( $field_values, $get_from_post_global_var = true ) {
if ( $get_from_post_global_var ) {
$value[ $this->id . '.1' ] = $this->get_input_value_submission( 'input_' . $this->id . '_1', rgar( $this->inputs[0], 'name' ), $field_values, true );
$value[ $this->id . '.2' ] = $this->get_input_value_submission( 'input_' . $this->id . '_2', rgar( $this->inputs[1], 'name' ), $field_values, true );
$value[ $this->id . '.3' ] = $this->get_input_value_submission( 'input_' . $this->id . '_3', rgar( $this->inputs[3], 'name' ), $field_values, true );
$value[ $this->id . '.4' ] = $this->get_input_value_submission( 'input_' . $this->id . '_4', rgar( $this->inputs[4], 'name' ), $field_values, true );
$value[ $this->id . '.5' ] = $this->get_input_value_submission( 'input_' . $this->id . '_5', rgar( $this->inputs[5], 'name' ), $field_values, true );
} else {
$value = $this->get_input_value_submission( 'input_' . $this->id, $this->inputName, $field_values, $get_from_post_global_var );
}
return $value;
}
/**
* Returns the HTML tag for the field container.
*
* @since 2.5
*
* @param array $form The current Form object.
*
* @return string
*/
public function get_field_container_tag( $form ) {
if ( GFCommon::is_legacy_markup_enabled( $form ) ) {
return parent::get_field_container_tag( $form );
}
return 'fieldset';
}
/**
* Displays an insecure page warning below the field content.
*
* @since 2.5
*
* @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission.
* @param bool $force_frontend_label Should the frontend label be displayed in the admin even if an admin label is configured.
* @param array $form The Form Object currently being processed.
*
* @return string
*/
public function get_field_content( $value, $force_frontend_label, $form ) {
$is_form_editor = GFCommon::is_form_editor();
$is_entry_detail = GFCommon::is_entry_detail();
$is_admin = $is_form_editor || $is_entry_detail;
// Get existing field content.
$field_content = parent::get_field_content( $value, $force_frontend_label, $form );
// If SSL is not used, display warning message.
if ( ! GFCommon::is_ssl() && ! $is_admin ) {
$field_content = "
id}_creditcard_warning_message'>" . esc_html__( 'This page is unsecured. Do not enter a real credit card number! Use this field only for testing purposes. ', 'gravityforms' ) . '