0

I have been working on a function and the validation is to ensure that input in the field is exactly what is in the $cash variable defined, i succeeded in using greater than function but this allows values greater than what the user has, so it does not get exact figure of what the user has, if user cash is 300 then anything above 300 is valid and okay, but i want the validation to be strictly on the value exactly.

add_filter( 'gform_field_validation_9_7', 'custom_validationc', 10, 4 );
function custom_validationc( $result, $value, $form, $field ) {

$current_user = wp_get_current_user();
$number = $current_user->USERPIN2;

if ( $result['is_valid'] && $value < $number ) {
    $result['is_valid'] = false;
    $result['message'] = 'You must enter exactly the amount on your cash balance.';
}
return $result;

}

My problem is that i want the exact value of $cash not by using greater than functions. And i have tried $value === $cash - But nothing works. only works when i use the greater than function or less than function for validation.

pandglobal
  • 31
  • 1
  • 9

1 Answers1

1

If it needs strictly validation, you need to use operator '===', more info is here: How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?

Also, you can use another conditions, so, the code may be like that:

if ( intval($value) === $cash )
  echo "perfect";

Or

if ( intval($value) >= $cash )
  echo "perfect";
Alexander Z
  • 630
  • 3
  • 22
  • i have updated my code to full codes so you can know where am going wrong and how to archive what i want exactly. – pandglobal Dec 23 '19 at 22:05