Joomla validation for empty string using JInput

Following this guide to misinform my inputs, I wonder if the empty string is covered by this?

$jinput = JFactory::getApplication()->input; $this->name = $jinput->get('name', '', 'STRING'); 

As a rule, without Joomla, I would also check for an empty string. Sort of:

 if (!empty($_POST['name'])) 

Looking at the JInput get method, I see that it checks if it is isset :

 public function get($name, $default = null, $filter = 'cmd') { if (isset($this->data[$name])) { return $this->filter->clean($this->data[$name], $filter); } return $default; } 

Not the same as isset will only check for null. However, this is the default value for using the get method. So, if I specify an empty string for the second parameter, which I examined here?

 $this->name = $jinput->get('name', '', 'STRING'); 
+4
source share
1 answer

It is not up to Joomla to decide if your empty string is a valid value or not. They should use isset() because if they use empty() and you return '0' , which you expect as normal, Joomla will return the default value instead of '0' .

So, it’s completely normal that they simply use isset() to check if the variable is set and decide for you what values ​​you are taking.

If the value is not set, and you set an empty string as the second parameter, you will get an empty string.

In your example, an empty string will be returned, the expected behavior.

+5
source

All Articles