Jump to content

[SOLVED] form help


darkfreaks

Recommended Posts

How are you using is_numeric?

 

This returns true for me.

 

<?php

if(is_numeric(0.0)) {
   echo "true";
} else {
   echo "false";
}

?>

that will because it is true .. is_numeric is not checking for integer values .. it's simply checking if the value/string in question is a number/numeric.

 

is_int() will check if the value/string is an integer and return true/false .. 0.0 will return false on and is_int() check.

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809846
Share on other sites

im doing something like :

<?php
if(!is_int($_POST['height)) { 
}?>

 

and:

<?php
if(is_int($_POST['height)) { 
}?>

 

o0ps yeah your right is_int() not numeric ;D

 

anyhow 0.0 returns false because of the dot right? thats what i dont want to allow. however if i type 12345 i still get  "numbers only allowed" which telling me its still returning false :-\

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809850
Share on other sites

im doing something like :

<?php
if(!is_int($_POST['height)) { 
}?>

 

and:

<?php
if(is_int($_POST['height)) { 
}?>

 

o0ps yeah your right is_int() not numeric ;D

 

anyhow 0.0 returns false because of the dot right? thats what i dont want to allow. however if i type 12345 i still get  "numbers only allowed" which telling me its still returning false :-\

typing 12345 will return true on an is_int() check .. typing '12345' will return false.  12345 cannot be treated as a string.  refer to my previous post though, and correct the syntax.
Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809856
Share on other sites

You're going to have to check multiple things.  Use this function:

 

function is_int_val($data) {
if (is_int($data) === true) return true;
elseif (is_string($data) === true && is_numeric($data) === true) {
   return (strpos($data, '.') === false);
}
   return false;
}

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809876
Share on other sites

that function is messing up my form it only returns "you are obese"

 

is there another way i could implement this ???

 

maybe instead of returning true or false to maybe echo "you cant enter dots"

 

i really dont understand the return part anyhow ???

Link to comment
https://forums.phpfreaks.com/topic/154056-solved-form-help/#findComment-809886
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.