0
votes

If I grab a value from my form in my controller using:

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

I expect the default value to be set as a string called Default name.

But if I test this it doesn't seem to think there is a value:

if (!empty($add_name))
{
    //do stuff
    //I expect to be here because $add_name="Default name"
}
else
{
    //I actually go here
}

Am I misunderstanding the default value?

EDIT

If a form is submitted with an empty string then that is what will be returned. I understand that (now). But under what circumstance will the default value Default name ever get assigned to $add_name

1

1 Answers

1
votes

If you submitted an empty string in your form, then it's used instead of the default value. JInput does isset() check, not empty(), so empty string is considered as a valid value.