", $id, $field_id, esc_attr( $value ), esc_attr( $class ), $disabled_text, $placeholder_attribute, $required_attribute, $invalid_attribute, $aria_describedby, $autocomplete_attribute, $instruction );
return $input;
}
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
$include_thousands_sep = apply_filters( 'gform_include_thousands_sep_pre_format_number', true, $this );
return GFCommon::format_number( $value, $this->numberFormat, rgar( $entry, 'currency' ), $include_thousands_sep );
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
$include_thousands_sep = apply_filters( 'gform_include_thousands_sep_pre_format_number', $use_text, $this );
return GFCommon::format_number( $value, $this->numberFormat, $currency, $include_thousands_sep );
}
/**
* Gets merge tag values.
*
* @since Unknown
* @access public
*
* @uses GFCommon::format_number()
*
* @param array|string $value The value of the input.
* @param string $input_id The input ID to use.
* @param array $entry The Entry Object.
* @param array $form The Form Object
* @param string $modifier The modifier passed.
* @param array|string $raw_value The raw value of the input.
* @param bool $url_encode If the result should be URL encoded.
* @param bool $esc_html If the HTML should be escaped.
* @param string $format The format that the value should be.
* @param bool $nl2br If the nl2br function should be used.
*
* @return string The processed merge tag.
*/
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
$include_thousands_sep = ! in_array( 'value', $this->get_modifiers() );
/**
* Filters if the thousands separator should be used when displaying the a number field result.
*
* @since 1.9.5
*
* @param bool $include_thousands_sep If the modifier passed in the merge tag is not 'value', false. Otherwise, true.
* @param GF_Field_Number $this An instance of this class.
*/
$include_thousands_sep = apply_filters( 'gform_include_thousands_sep_pre_format_number', $include_thousands_sep, $this );
$formatted_value = GFCommon::format_number( $value, $this->numberFormat, rgar( $entry, 'currency' ), $include_thousands_sep );
return $url_encode ? urlencode( $formatted_value ) : $formatted_value;
}
public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) {
if ( $this->has_calculation() ) {
if ( empty( $lead ) ) {
$lead = GFFormsModel::get_lead( $lead_id );
}
$value = GFCommon::calculate( $this, $form, $lead );
if ( $this->numberFormat !== 'currency' ) {
$value = GFCommon::round_number( $value, $this->calculationRounding );
}
// Return the value as a string when it is zero and a calc so that the "==" comparison done when checking if the field has changed isn't treated as false.
if ( $value == 0 ) {
$value = '0';
}
} else {
$value = $this->clean_number( GFCommon::maybe_add_leading_zero( $value ) );
}
return $this->sanitize_entry_value( $value, $form['id'] );
}
public function sanitize_settings() {
parent::sanitize_settings();
$this->enableCalculation = (bool) $this->enableCalculation;
if ( ! in_array( $this->numberFormat, array( 'currency', 'decimal_comma', 'decimal_dot' ) ) ) {
$this->numberFormat = GFCommon::is_currency_decimal_dot() ? 'decimal_dot' : 'decimal_comma';
}
$this->rangeMin = $this->clean_number( $this->rangeMin );
$this->rangeMax = $this->clean_number( $this->rangeMax );
if ( $this->numberFormat == 'decimal_comma' ) {
$this->rangeMin = GFCommon::format_number( $this->rangeMin, 'decimal_comma' );
$this->rangeMax = GFCommon::format_number( $this->rangeMax, 'decimal_comma' );
}
}
public function clean_number( $value ) {
if ( $this->numberFormat == 'currency' ) {
return GFCommon::to_number( $value );
} else {
return GFCommon::clean_number( $value, $this->numberFormat );
}
}
}
GF_Fields::register( new GF_Field_Number() );