Joomla: Passing a variable into getInput()

joomla, joomla1.6, joomla1.7, joomla2.5, php

Solution

According to the source, this is the correct API:

getInput($name, $group = null, $value = null)

And `getInput()` just calls `getField()`:

getField($name, $group = null, $value = null)

Which means you should be doing this to set a default value:

echo $this->form->getInput('id', null, $this->userID ); // Returns the $field->input String

Or:

$field = $this->form->getField('id', null, $this->userID ); // Returns the JFormField object

Problem

I'm building a backend component (1.6 / 1.7 / 2.5) where I need to pass a variable from another view into a field in a new record. Variable passing is working fine. My problem is using getInput(). To start with different doc pages have different amounts and formatting of parameters - confusing! For example: http://docs.joomla.org/API16:JForm/getInput: `getInput($name, $group= '_default', $formControl= '_default', $groupControl= '_default', $value=null)` vs http://docs.joomla.org/JForm::getInput/1.6: ``` public function getInput ( $name $group=null $value=null ) ``` The problem: I just need to pass a variable as a default value, something like: `echo $this->form->getInput('id', $value=$this->userID );?>` The above code makes the input field disappear. If I take out the `$value=$this->userID` the input field shows up though obviously doesn't have any default value. I've also tried: ``` $value=$this->userID; echo $this->form->getInput('id', $value ); ``` And same problem, the input field goes away. I tried a few other variations but basically if I try to put anything else within getInput() it doesn't work nor can I find any good working examples of how to use these other parameters. What am I doing wrong? Thanks!

Original source