| Server IP : 198.54.126.161 / Your IP : 216.73.216.116 Web Server : LiteSpeed System : Linux premium12.web-hosting.com 4.18.0-553.94.1.lve.el8.x86_64 #1 SMP Thu Jan 22 12:37:22 UTC 2026 x86_64 User : amerfigf ( 898) PHP Version : 8.2.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/cwd/wp-content/plugins/WP-FormBuilder/admin/classes/fields/ |
Upload File : |
<?php
defined('ABSPATH') || die();
class HashFormFieldRangeSlider extends HashFormFieldType {
protected $type = 'range_slider';
public function field_settings_for_type() {
return array(
'range' => true
);
}
public function validate($args) {
$errors = array();
if (!is_numeric($args['value']) && '' !== $args['value'])
$errors['field' . $args['id']] = HashFormFields::get_error_msg($this->field, 'invalid');
if ($args['value'] != '') {
$minnum = HashFormFields::get_option($this->field, 'minnum');
$maxnum = HashFormFields::get_option($this->field, 'maxnum');
if ($maxnum !== '' && $minnum !== '') {
$value = (float) $args['value'];
if ($value < $minnum) {
$errors['field' . $args['id']] = esc_html__('Please select a higher number', 'hash-form');
} elseif ($value > $maxnum) {
$errors['field' . $args['id']] = esc_html__('Please select a lower number', 'hash-form');
}
}
$this->validate_step($errors, $args);
}
return $errors;
}
private function validate_step(&$errors, $args) {
if (isset($errors['field' . $args['id']])) {
return;
}
$step = HashFormFields::get_option($this->field, 'step');
if (!$step || !is_numeric($step)) {
return;
}
$result = $this->check_value_is_valid_with_step($args['value'], $step);
if (!$result) {
return;
}
$errors['field' . $args['id']] = sprintf(__('Please enter a valid value. Two nearest valid values are %1$s and %2$s', 'hash-form'), floatval($result[0]), floatval($result[1]));
}
private function check_value_is_valid_with_step($value, $step) {
$decimals = max(HashFormHelper::count_decimals($value), HashFormHelper::count_decimals($step));
$pow = pow(10, $decimals);
$value = intval($pow * $value);
$step = intval($pow * $step);
$div = $value / $step;
if (is_int($div)) {
return 0;
}
$div = floor($div);
return array($div * $step / $pow, ( $div + 1 ) * $step / $pow);
}
public function sanitize_value(&$value) {
return hashform_sanitize_float($value);
}
protected function input_html() {
$field = $this->get_field();
?>
<div class="hashform-range-slider-container">
<div class="hashform-range-slider-wrap">
<div class="hashform-range-slider"></div>
<input class="hashform-range-input-selector" type="number" <?php $this->field_attrs(); ?>>
</div>
</div>
<?php
}
}