Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/wpforms-.../src/Forms/Fields/PaymentM...
File: Field.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Forms\Fields\PaymentMultiple;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Radio payment field.
[5] Fix | Delete
*
[6] Fix | Delete
* @since 1.8.2
[7] Fix | Delete
*/
[8] Fix | Delete
class Field extends \WPForms_Field {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Primary class constructor.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 1.8.2
[14] Fix | Delete
*/
[15] Fix | Delete
public function init() {
[16] Fix | Delete
[17] Fix | Delete
// Define field type information.
[18] Fix | Delete
$this->name = esc_html__( 'Multiple Items', 'wpforms-lite' );
[19] Fix | Delete
$this->keywords = esc_html__( 'product, store, ecommerce, pay, payment', 'wpforms-lite' );
[20] Fix | Delete
$this->type = 'payment-multiple';
[21] Fix | Delete
$this->icon = 'fa-list-ul';
[22] Fix | Delete
$this->order = 50;
[23] Fix | Delete
$this->group = 'payment';
[24] Fix | Delete
$this->defaults = [
[25] Fix | Delete
1 => [
[26] Fix | Delete
'label' => esc_html__( 'First Item', 'wpforms-lite' ),
[27] Fix | Delete
'value' => '10',
[28] Fix | Delete
'icon' => '',
[29] Fix | Delete
'icon_style' => '',
[30] Fix | Delete
'image' => '',
[31] Fix | Delete
'default' => '',
[32] Fix | Delete
],
[33] Fix | Delete
2 => [
[34] Fix | Delete
'label' => esc_html__( 'Second Item', 'wpforms-lite' ),
[35] Fix | Delete
'value' => '25',
[36] Fix | Delete
'icon' => '',
[37] Fix | Delete
'icon_style' => '',
[38] Fix | Delete
'image' => '',
[39] Fix | Delete
'default' => '',
[40] Fix | Delete
],
[41] Fix | Delete
3 => [
[42] Fix | Delete
'label' => esc_html__( 'Third Item', 'wpforms-lite' ),
[43] Fix | Delete
'value' => '50',
[44] Fix | Delete
'icon' => '',
[45] Fix | Delete
'icon_style' => '',
[46] Fix | Delete
'image' => '',
[47] Fix | Delete
'default' => '',
[48] Fix | Delete
],
[49] Fix | Delete
];
[50] Fix | Delete
[51] Fix | Delete
$this->hooks();
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Register hooks.
[56] Fix | Delete
*
[57] Fix | Delete
* @since 1.8.1
[58] Fix | Delete
*/
[59] Fix | Delete
private function hooks() {
[60] Fix | Delete
[61] Fix | Delete
// Customize HTML field values.
[62] Fix | Delete
add_filter( 'wpforms_html_field_value', [ $this, 'field_html_value' ], 10, 4 );
[63] Fix | Delete
[64] Fix | Delete
// Define additional field properties.
[65] Fix | Delete
add_filter( "wpforms_field_properties_{$this->type}", [ $this, 'field_properties' ], 5, 3 );
[66] Fix | Delete
[67] Fix | Delete
// This field requires fieldset+legend instead of the field label.
[68] Fix | Delete
add_filter( "wpforms_frontend_modern_is_field_requires_fieldset_{$this->type}", '__return_true', PHP_INT_MAX, 2 );
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Define additional field properties.
[73] Fix | Delete
*
[74] Fix | Delete
* @since 1.8.2
[75] Fix | Delete
*
[76] Fix | Delete
* @param array $properties Field properties.
[77] Fix | Delete
* @param array $field Field settings.
[78] Fix | Delete
* @param array $form_data Form data and settings.
[79] Fix | Delete
*
[80] Fix | Delete
* @return array
[81] Fix | Delete
*/
[82] Fix | Delete
public function field_properties( $properties, $field, $form_data ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
[83] Fix | Delete
[84] Fix | Delete
// Define data.
[85] Fix | Delete
$form_id = absint( $form_data['id'] );
[86] Fix | Delete
$field_id = absint( $field['id'] );
[87] Fix | Delete
$choices = $field['choices'];
[88] Fix | Delete
[89] Fix | Delete
// Remove primary input.
[90] Fix | Delete
unset( $properties['inputs']['primary'] );
[91] Fix | Delete
[92] Fix | Delete
// Set input container (ul) properties.
[93] Fix | Delete
$properties['input_container'] = [
[94] Fix | Delete
'class' => [],
[95] Fix | Delete
'data' => [],
[96] Fix | Delete
'attr' => [],
[97] Fix | Delete
'id' => "wpforms-{$form_id}-field_{$field_id}",
[98] Fix | Delete
];
[99] Fix | Delete
[100] Fix | Delete
// Set input properties.
[101] Fix | Delete
foreach ( $choices as $key => $choice ) {
[102] Fix | Delete
[103] Fix | Delete
$properties['inputs'][ $key ] = [
[104] Fix | Delete
'container' => [
[105] Fix | Delete
'attr' => [],
[106] Fix | Delete
'class' => [ "choice-{$key}" ],
[107] Fix | Delete
'data' => [],
[108] Fix | Delete
'id' => '',
[109] Fix | Delete
],
[110] Fix | Delete
'label' => [
[111] Fix | Delete
'attr' => [
[112] Fix | Delete
'for' => "wpforms-{$form_id}-field_{$field_id}_{$key}",
[113] Fix | Delete
],
[114] Fix | Delete
'class' => [ 'wpforms-field-label-inline' ],
[115] Fix | Delete
'data' => [],
[116] Fix | Delete
'id' => '',
[117] Fix | Delete
'text' => $choice['label'],
[118] Fix | Delete
],
[119] Fix | Delete
'attr' => [
[120] Fix | Delete
'name' => "wpforms[fields][{$field_id}]",
[121] Fix | Delete
'value' => $key,
[122] Fix | Delete
],
[123] Fix | Delete
'class' => [ 'wpforms-payment-price' ],
[124] Fix | Delete
'data' => [
[125] Fix | Delete
'amount' => wpforms_format_amount( wpforms_sanitize_amount( $choice['value'] ) ),
[126] Fix | Delete
],
[127] Fix | Delete
'id' => "wpforms-{$form_id}-field_{$field_id}_{$key}",
[128] Fix | Delete
'icon' => isset( $choice['icon'] ) ? $choice['icon'] : '',
[129] Fix | Delete
'icon_style' => isset( $choice['icon_style'] ) ? $choice['icon_style'] : '',
[130] Fix | Delete
'image' => isset( $choice['image'] ) ? $choice['image'] : '',
[131] Fix | Delete
'required' => ! empty( $field['required'] ) ? 'required' : '',
[132] Fix | Delete
'default' => isset( $choice['default'] ),
[133] Fix | Delete
];
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
// Required class for pagebreak validation.
[137] Fix | Delete
if ( ! empty( $field['required'] ) ) {
[138] Fix | Delete
$properties['input_container']['class'][] = 'wpforms-field-required';
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
// Custom properties if image choices are enabled.
[142] Fix | Delete
if ( ! empty( $field['choices_images'] ) ) {
[143] Fix | Delete
[144] Fix | Delete
$properties['input_container']['class'][] = 'wpforms-image-choices';
[145] Fix | Delete
$properties['input_container']['class'][] = 'wpforms-image-choices-' . sanitize_html_class( $field['choices_images_style'] );
[146] Fix | Delete
[147] Fix | Delete
foreach ( $properties['inputs'] as $key => $inputs ) {
[148] Fix | Delete
$properties['inputs'][ $key ]['container']['class'][] = 'wpforms-image-choices-item';
[149] Fix | Delete
[150] Fix | Delete
if ( in_array( $field['choices_images_style'], [ 'modern', 'classic' ], true ) ) {
[151] Fix | Delete
$properties['inputs'][ $key ]['class'][] = 'wpforms-screen-reader-element';
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
} elseif ( ! empty( $field['choices_icons'] ) ) {
[155] Fix | Delete
$properties = wpforms()->get( 'icon_choices' )->field_properties( $properties, $field );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
// Add selected class for choices with defaults.
[159] Fix | Delete
foreach ( $properties['inputs'] as $key => $inputs ) {
[160] Fix | Delete
if ( ! empty( $inputs['default'] ) ) {
[161] Fix | Delete
$properties['inputs'][ $key ]['container']['class'][] = 'wpforms-selected';
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
return $properties;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Get field populated single property value.
[170] Fix | Delete
*
[171] Fix | Delete
* @since 1.8.2
[172] Fix | Delete
*
[173] Fix | Delete
* @param string $raw_value Value from a GET param, always a string.
[174] Fix | Delete
* @param string $input Represent a subfield inside the field. May be empty.
[175] Fix | Delete
* @param array $properties Field properties.
[176] Fix | Delete
* @param array $field Current field specific data.
[177] Fix | Delete
*
[178] Fix | Delete
* @return array Modified field properties.
[179] Fix | Delete
*/
[180] Fix | Delete
protected function get_field_populated_single_property_value( $raw_value, $input, $properties, $field ) {
[181] Fix | Delete
/*
[182] Fix | Delete
* When the form is submitted we get only values (prices) from the Fallback.
[183] Fix | Delete
* As payment-multiple (radio) field doesn't support 'show_values' option -
[184] Fix | Delete
* we should transform value into label to check against using general logic in parent method.
[185] Fix | Delete
*/
[186] Fix | Delete
[187] Fix | Delete
if (
[188] Fix | Delete
! is_string( $raw_value ) ||
[189] Fix | Delete
empty( $field['choices'] ) ||
[190] Fix | Delete
! is_array( $field['choices'] )
[191] Fix | Delete
) {
[192] Fix | Delete
return $properties;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
// The form submits only the sum, so shortcut for Dynamic.
[196] Fix | Delete
if ( ! is_numeric( $raw_value ) ) {
[197] Fix | Delete
return parent::get_field_populated_single_property_value( $raw_value, $input, $properties, $field );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
$get_value = wpforms_format_amount( wpforms_sanitize_amount( $raw_value ) );
[201] Fix | Delete
[202] Fix | Delete
foreach ( $field['choices'] as $choice ) {
[203] Fix | Delete
if (
[204] Fix | Delete
isset( $choice['label'], $choice['value'] ) &&
[205] Fix | Delete
wpforms_format_amount( wpforms_sanitize_amount( $choice['value'] ) ) === $get_value
[206] Fix | Delete
) {
[207] Fix | Delete
$trans_value = $choice['label'];
[208] Fix | Delete
// Stop iterating over choices.
[209] Fix | Delete
break;
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
if ( empty( $trans_value ) ) {
[214] Fix | Delete
return $properties;
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
return parent::get_field_populated_single_property_value( $trans_value, $input, $properties, $field );
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
/**
[221] Fix | Delete
* Field options panel inside the builder.
[222] Fix | Delete
*
[223] Fix | Delete
* @since 1.8.2
[224] Fix | Delete
*
[225] Fix | Delete
* @param array $field Field settings.
[226] Fix | Delete
*/
[227] Fix | Delete
public function field_options( $field ) {
[228] Fix | Delete
/*
[229] Fix | Delete
* Basic field options.
[230] Fix | Delete
*/
[231] Fix | Delete
[232] Fix | Delete
// Options open markup.
[233] Fix | Delete
$this->field_option(
[234] Fix | Delete
'basic-options',
[235] Fix | Delete
$field,
[236] Fix | Delete
[
[237] Fix | Delete
'markup' => 'open',
[238] Fix | Delete
]
[239] Fix | Delete
);
[240] Fix | Delete
[241] Fix | Delete
// Label.
[242] Fix | Delete
$this->field_option( 'label', $field );
[243] Fix | Delete
[244] Fix | Delete
// Choices option.
[245] Fix | Delete
$this->field_option( 'choices_payments', $field );
[246] Fix | Delete
[247] Fix | Delete
// Show price after item labels.
[248] Fix | Delete
$fld = $this->field_element(
[249] Fix | Delete
'toggle',
[250] Fix | Delete
$field,
[251] Fix | Delete
[
[252] Fix | Delete
'slug' => 'show_price_after_labels',
[253] Fix | Delete
'value' => isset( $field['show_price_after_labels'] ) ? '1' : '0',
[254] Fix | Delete
'desc' => esc_html__( 'Show price after item labels', 'wpforms-lite' ),
[255] Fix | Delete
'tooltip' => esc_html__( 'Check this option to show price of the item after the label.', 'wpforms-lite' ),
[256] Fix | Delete
],
[257] Fix | Delete
false
[258] Fix | Delete
);
[259] Fix | Delete
$args = [
[260] Fix | Delete
'slug' => 'show_price_after_labels',
[261] Fix | Delete
'content' => $fld,
[262] Fix | Delete
];
[263] Fix | Delete
[264] Fix | Delete
$this->field_element( 'row', $field, $args );
[265] Fix | Delete
[266] Fix | Delete
// Choices Images.
[267] Fix | Delete
$this->field_option( 'choices_images', $field );
[268] Fix | Delete
[269] Fix | Delete
// Choices Images Style (theme).
[270] Fix | Delete
$this->field_option( 'choices_images_style', $field );
[271] Fix | Delete
[272] Fix | Delete
// Choices Icons.
[273] Fix | Delete
$this->field_option( 'choices_icons', $field );
[274] Fix | Delete
[275] Fix | Delete
// Choices Icons Color.
[276] Fix | Delete
$this->field_option( 'choices_icons_color', $field );
[277] Fix | Delete
[278] Fix | Delete
// Choices Icons Size.
[279] Fix | Delete
$this->field_option( 'choices_icons_size', $field );
[280] Fix | Delete
[281] Fix | Delete
// Choices Icons Style.
[282] Fix | Delete
$this->field_option( 'choices_icons_style', $field );
[283] Fix | Delete
[284] Fix | Delete
// Description.
[285] Fix | Delete
$this->field_option( 'description', $field );
[286] Fix | Delete
[287] Fix | Delete
// Required toggle.
[288] Fix | Delete
$this->field_option( 'required', $field );
[289] Fix | Delete
[290] Fix | Delete
// Options close markup.
[291] Fix | Delete
$this->field_option(
[292] Fix | Delete
'basic-options',
[293] Fix | Delete
$field,
[294] Fix | Delete
[
[295] Fix | Delete
'markup' => 'close',
[296] Fix | Delete
]
[297] Fix | Delete
);
[298] Fix | Delete
[299] Fix | Delete
/*
[300] Fix | Delete
* Advanced field options.
[301] Fix | Delete
*/
[302] Fix | Delete
[303] Fix | Delete
// Options open markup.
[304] Fix | Delete
$this->field_option(
[305] Fix | Delete
'advanced-options',
[306] Fix | Delete
$field,
[307] Fix | Delete
[
[308] Fix | Delete
'markup' => 'open',
[309] Fix | Delete
]
[310] Fix | Delete
);
[311] Fix | Delete
[312] Fix | Delete
// Input columns.
[313] Fix | Delete
$this->field_option( 'input_columns', $field );
[314] Fix | Delete
[315] Fix | Delete
// Custom CSS classes.
[316] Fix | Delete
$this->field_option( 'css', $field );
[317] Fix | Delete
[318] Fix | Delete
// Hide label.
[319] Fix | Delete
$this->field_option( 'label_hide', $field );
[320] Fix | Delete
[321] Fix | Delete
// Options close markup.
[322] Fix | Delete
$this->field_option(
[323] Fix | Delete
'advanced-options',
[324] Fix | Delete
$field,
[325] Fix | Delete
[
[326] Fix | Delete
'markup' => 'close',
[327] Fix | Delete
]
[328] Fix | Delete
);
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
/**
[332] Fix | Delete
* Field preview inside the builder.
[333] Fix | Delete
*
[334] Fix | Delete
* @since 1.8.2
[335] Fix | Delete
*
[336] Fix | Delete
* @param array $field Field settings.
[337] Fix | Delete
*/
[338] Fix | Delete
public function field_preview( $field ) {
[339] Fix | Delete
[340] Fix | Delete
// Label.
[341] Fix | Delete
$this->field_preview_option( 'label', $field );
[342] Fix | Delete
[343] Fix | Delete
// Choices.
[344] Fix | Delete
$this->field_preview_option( 'choices', $field );
[345] Fix | Delete
[346] Fix | Delete
// Description.
[347] Fix | Delete
$this->field_preview_option( 'description', $field );
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
/**
[351] Fix | Delete
* Field display on the form front-end.
[352] Fix | Delete
*
[353] Fix | Delete
* @since 1.8.2
[354] Fix | Delete
*
[355] Fix | Delete
* @param array $field Field settings.
[356] Fix | Delete
* @param array $deprecated Deprecated array.
[357] Fix | Delete
* @param array $form_data Form data and settings.
[358] Fix | Delete
*/
[359] Fix | Delete
public function field_display( $field, $deprecated, $form_data ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
[360] Fix | Delete
[361] Fix | Delete
// Define data.
[362] Fix | Delete
$container = $field['properties']['input_container'];
[363] Fix | Delete
$choices = $field['properties']['inputs'];
[364] Fix | Delete
[365] Fix | Delete
printf(
[366] Fix | Delete
'<ul %s>',
[367] Fix | Delete
wpforms_html_attributes( $container['id'], $container['class'], $container['data'], $container['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[368] Fix | Delete
);
[369] Fix | Delete
[370] Fix | Delete
foreach ( $choices as $key => $choice ) {
[371] Fix | Delete
[372] Fix | Delete
$label = isset( $choice['label']['text'] ) ? $choice['label']['text'] : '';
[373] Fix | Delete
/* translators: %s - item number. */
[374] Fix | Delete
$label = $label !== '' ? $label : sprintf( esc_html__( 'Item %s', 'wpforms-lite' ), $key );
[375] Fix | Delete
$label .= ! empty( $field['show_price_after_labels'] ) && isset( $choice['data']['amount'] ) ? ' - ' . wpforms_format_amount( wpforms_sanitize_amount( $choice['data']['amount'] ), true ) : '';
[376] Fix | Delete
[377] Fix | Delete
printf(
[378] Fix | Delete
'<li %s>',
[379] Fix | Delete
wpforms_html_attributes( $choice['container']['id'], $choice['container']['class'], $choice['container']['data'], $choice['container']['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[380] Fix | Delete
);
[381] Fix | Delete
[382] Fix | Delete
if ( empty( $field['dynamic_choices'] ) && ! empty( $field['choices_images'] ) ) {
[383] Fix | Delete
[384] Fix | Delete
// Image choices.
[385] Fix | Delete
printf(
[386] Fix | Delete
'<label %s>',
[387] Fix | Delete
wpforms_html_attributes( $choice['label']['id'], $choice['label']['class'], $choice['label']['data'], $choice['label']['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[388] Fix | Delete
);
[389] Fix | Delete
[390] Fix | Delete
echo '<span class="wpforms-image-choices-image">';
[391] Fix | Delete
[392] Fix | Delete
if ( ! empty( $choice['image'] ) ) {
[393] Fix | Delete
printf(
[394] Fix | Delete
'<img src="%s" alt="%s"%s>',
[395] Fix | Delete
esc_url( $choice['image'] ),
[396] Fix | Delete
esc_attr( $choice['label']['text'] ),
[397] Fix | Delete
! empty( $choice['label']['text'] ) ? ' title="' . esc_attr( $choice['label']['text'] ) . '"' : ''
[398] Fix | Delete
);
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
echo '</span>';
[402] Fix | Delete
[403] Fix | Delete
if ( $field['choices_images_style'] === 'none' ) {
[404] Fix | Delete
echo '<br>';
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
printf(
[408] Fix | Delete
'<input type="radio" %s %s %s>',
[409] Fix | Delete
wpforms_html_attributes( $choice['id'], $choice['class'], $choice['data'], $choice['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[410] Fix | Delete
esc_attr( $choice['required'] ),
[411] Fix | Delete
checked( '1', $choice['default'], false )
[412] Fix | Delete
);
[413] Fix | Delete
[414] Fix | Delete
echo '<span class="wpforms-image-choices-label">' . wp_kses_post( $label ) . '</span>';
[415] Fix | Delete
[416] Fix | Delete
echo '</label>';
[417] Fix | Delete
[418] Fix | Delete
} elseif ( empty( $field['dynamic_choices'] ) && ! empty( $field['choices_icons'] ) ) {
[419] Fix | Delete
$choice['attr']['autocomplete'] = 'off';
[420] Fix | Delete
[421] Fix | Delete
// Icon Choices.
[422] Fix | Delete
wpforms()->get( 'icon_choices' )->field_display( $field, $choice, 'radio', $label );
[423] Fix | Delete
[424] Fix | Delete
} else {
[425] Fix | Delete
[426] Fix | Delete
// Normal display.
[427] Fix | Delete
printf(
[428] Fix | Delete
'<input type="radio" %s %s %s>',
[429] Fix | Delete
wpforms_html_attributes( $choice['id'], $choice['class'], $choice['data'], $choice['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[430] Fix | Delete
esc_attr( $choice['required'] ),
[431] Fix | Delete
checked( '1', $choice['default'], false )
[432] Fix | Delete
);
[433] Fix | Delete
[434] Fix | Delete
printf(
[435] Fix | Delete
'<label %s>%s</label>',
[436] Fix | Delete
wpforms_html_attributes( $choice['label']['id'], $choice['label']['class'], $choice['label']['data'], $choice['label']['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[437] Fix | Delete
wp_kses_post( $label )
[438] Fix | Delete
);
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
echo '</li>';
[442] Fix | Delete
}
[443] Fix | Delete
[444] Fix | Delete
echo '</ul>';
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
/**
[448] Fix | Delete
* Validate field on form submit.
[449] Fix | Delete
*
[450] Fix | Delete
* @since 1.8.2
[451] Fix | Delete
*
[452] Fix | Delete
* @param int $field_id Field ID.
[453] Fix | Delete
* @param array $field_submit Submitted field value (raw data).
[454] Fix | Delete
* @param array $form_data Form data and settings.
[455] Fix | Delete
*/
[456] Fix | Delete
public function validate( $field_id, $field_submit, $form_data ) {
[457] Fix | Delete
[458] Fix | Delete
// Basic required check - If field is marked as required, check for entry data.
[459] Fix | Delete
if ( ! empty( $form_data['fields'][ $field_id ]['required'] ) && empty( $field_submit ) ) {
[460] Fix | Delete
[461] Fix | Delete
wpforms()->get( 'process' )->errors[ $form_data['id'] ][ $field_id ] = wpforms_get_required_label();
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
// Validate that the option selected is real.
[465] Fix | Delete
if ( ! empty( $field_submit ) && empty( $form_data['fields'][ $field_id ]['choices'][ $field_submit ] ) ) {
[466] Fix | Delete
wpforms()->get( 'process' )->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'Invalid payment option.', 'wpforms-lite' );
[467] Fix | Delete
}
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
/**
[471] Fix | Delete
* Format and sanitize field.
[472] Fix | Delete
*
[473] Fix | Delete
* @since 1.8.2
[474] Fix | Delete
*
[475] Fix | Delete
* @param int $field_id Field ID.
[476] Fix | Delete
* @param string $field_submit Submitted form data.
[477] Fix | Delete
* @param array $form_data Form data and settings.
[478] Fix | Delete
*/
[479] Fix | Delete
public function format( $field_id, $field_submit, $form_data ) {
[480] Fix | Delete
[481] Fix | Delete
$field = $form_data['fields'][ $field_id ];
[482] Fix | Delete
$name = sanitize_text_field( $field['label'] );
[483] Fix | Delete
$value = '';
[484] Fix | Delete
$amount = 0;
[485] Fix | Delete
$choice_label = '';
[486] Fix | Delete
$image = '';
[487] Fix | Delete
[488] Fix | Delete
if ( ! empty( $field_submit ) && ! empty( $field['choices'][ $field_submit ] ) ) {
[489] Fix | Delete
[490] Fix | Delete
$amount = wpforms_sanitize_amount( $field['choices'][ $field_submit ]['value'] );
[491] Fix | Delete
$value = wpforms_format_amount( $amount, true );
[492] Fix | Delete
[493] Fix | Delete
if ( ! empty( $field['choices'][ $field_submit ]['label'] ) ) {
[494] Fix | Delete
$choice_label = sanitize_text_field( $field['choices'][ $field_submit ]['label'] );
[495] Fix | Delete
$value = $choice_label . ' - ' . $value;
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
if ( ! empty( $field['choices_images'] ) ) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function