1
votes

I'm retrieving a value from JInput that must be a integer.

$input = new JInput();
$post = $input->getArray($_POST);
$value= $input->$post['value'];

Now obviously I can't use is_int() because $_POST makes the value a string - usually solved with filter_input(). That leaves me in a slight issue - as I want to reject anything that isn't a integer - not convert it into an integer. Using something along the lines of

$value=JFactory::getApplication()->input->get('value', '0', 'INT');

forces the string to be a integer. (e.g. inputting 1.2 will then give a $value of 1 etc.). So I'm stuck as to how to achieve this filter. Ideally I'd like to do something along the lines of

if(is_int($delete)) {
    //Carry on processing data
} else {
    //Stop function and display a JError
JLog::add("Value is not a integer", JLog::WARNING, 'jerror');
}
3

3 Answers

0
votes

Why not use:

$input = new JInput;
$value = $input->getInt('value');
0
votes

Finally found it on SO under check for integer or float values.

Final code used was:

$input = new JInput();
$post = $input->getArray($_POST);
$value= $input->$post['value'];
//checks value is numeric and if it is a int
if(is_numeric($value) && (int) $value == $value) {
    //process data
} else {
    JLog::add("Value is not a integer", JLog::WARNING, 'jerror');
}
0
votes
$input = new JInput;
$email = $input->get('email', '', 'post');
$time = $input->get('time', '', 'post');
$move = $input->get('move', '', 'post');
$idcat = $input->get('idcat', '', 'post');