Jinput always returns "Array"

Status
Not open for further replies.

jmdc

Member
Hello,

I am trying to debug the code above and it always shows me "Array" in form?s top.
I am just trying to echo the value that is inserted into {fichapedagogica___Alunopedagogicaaescolher}.

PHP Code validation:

$jinput = JFactory::getApplication()->input;
$p = $jinput->get('fichapedagogica___Alunopedagogicaaescolher');
echo $p;

This {fichapedagogica___Alunopedagogicaaescolher} element is a databasejoin element.
Any idea why it doesn?t echo the data inserted into this element?

Thank you.
 
Joins always return arrays. Basically any element type which uses dropdowns, checkboxes or radio buttons will be an array. If it's a single select, like a dropdown, you can just grab the first entry.

So do something like this ...
Code:
$p = $jinput->get('fichapedagogica___Alunopedagogicaaescolher');
$p = is_array($p) ? $p[0] : $p;

You could just do $p = $p[0], but it's good to be in the habit of testing if an input is actually an array before accessing it.

-- hugh
 
BTW, it's usually better to get our form data using $formModel->getElementData('table___element'). If you want the raw data, add a second argument of true.

-- hugh
 
It works...thank you...
I have put this code:

$db = JFactory::getDBO();
defined('_JEXEC') or die();
$p = $formModel->getElementData('fichapedagogica___Alunopedagogicaaescolher', true);
$p = is_array($p) ? $p[0] : $p;
echo $p;
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top