You are here

function blockanimate_validate_positive_float_field in BlockAnimate 7

Helper function: validates optional positive float form fields.

1 string reference to 'blockanimate_validate_positive_float_field'
_blockanimate_add_form_wow_js_fields in ./blockanimate.module
Helper function: adds WOW JS related fields to the block configuration form.

File

./blockanimate.module, line 191
Add CSS3 cross-browser animation to any Drupal block.

Code

function blockanimate_validate_positive_float_field($element, &$form_state, $form) {
  $field_value = $element['#value'];
  if (strlen($field_value) > 0) {

    // The field is only validated when not left blank.
    $is_not_numeric = !is_numeric($field_value);
    $is_not_float_value = strval(floatval($field_value)) != $field_value;
    $is_not_positive = floatval($field_value) <= 0;
    if ($is_not_numeric || $is_not_float_value || $is_not_positive) {
      form_error($element, t('@field_name This field must be a positive float number. Examples: 0.5, 2, 4.35', array(
        '@field_name' => $element['#title'],
      )));
    }
  }
}