Getting input in controller Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
david0058
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 106
Joined: Wed Jan 20, 2016 10:58 pm

Getting input in controller

Post by david0058 » Fri Oct 29, 2021 10:58 am

J3.10.3

Hi all,

I've been struggling to see a problem for the last day, and I'm missing something ...

Basically I have a standard Joomla component, and when the form in the view is submitted, the controller class save() function is called. (This is needed because I want to override the standard behaviour.)

Code: Select all

class Conlucra_GameControllerAnswer extends JControllerAdmin
{
    /**
     * @var    string  The prefix to use with controller messages.
     * @since  1.6
     */
    protected $text_prefix = 'COM_CONLUCRA_GAME';

    /**
     * Constructor.
     *
     * @param   array  $config  An optional associative array of configuration settings.
     *
     * @since   1.6
     * @see     JController
     */
    public function __construct($config = array())
    {   
        parent::__construct($config);
    }

    /**
     * Proxy for getModel.
     *
     * @param   string  $name    The name of the model.
     * @param   string  $prefix  The prefix of the model.
     * @param   array   $config  An array of settings.
     *
     * @return  JModel instance
     *
     * @since   1.6
     */
    public function getModel($name = 'Answer', $prefix = 'Conlucra_GameModel', $config = array('ignore_request' => true))
    {   
        return parent::getModel($name, $prefix, $config);
    }

    public function save()
    {   
        var_dump($this->input);
        
        $data = $this->input->get('data', array(), 'array');
        var_dump($this->input->get('challenge_text'));
        
        die("done");
    }
}
The data that is submitted is in the input as expected, as confirmed by the fact that it appears in the first var_dump (see the line 'jform' => array (size=100) 'challenge_text' => string 'badgers' (length=7)):

Code: Select all

/var/www/game.conlucra.com/public_html/components/com_conlucra_game/controllers/answer.php:70:
object(Joomla\CMS\Input\Input)[18]
  protected 'inputs' => 
    array (size=100)
      'cookie' => 
        object(Joomla\CMS\Input\Cookie)[35]
          protected 'inputs' => 
            array (size=0)
              ...
          protected 'options' => 
            array (size=0)
              ...
          protected 'filter' => 
            object(Joomla\CMS\Filter\InputFilter)[19]
              ...
          protected 'data' => 
            array (size=100)
              ...
  protected 'options' => 
    array (size=0)
      empty
  protected 'filter' => 
    object(Joomla\Filter\InputFilter)[24]
      public 'tagsArray' => 
        array (size=0)
          empty
      public 'attrArray' => 
        array (size=0)
          empty
      public 'tagsMethod' => int 0
      public 'attrMethod' => int 0
      public 'xssAuto' => int 1
      public 'tagBlacklist' => 
        array (size=100)
          0 => string 'applet' (length=6)
          1 => string 'body' (length=4)
          2 => string 'bgsound' (length=7)
          3 => string 'base' (length=4)
          4 => string 'basefont' (length=8)
          5 => string 'canvas' (length=6)
          6 => string 'embed' (length=5)
          7 => string 'frame' (length=5)
          8 => string 'frameset' (length=8)
          9 => string 'head' (length=4)
          10 => string 'html' (length=4)
          11 => string 'id' (length=2)
          12 => string 'iframe' (length=6)
          13 => string 'ilayer' (length=6)
          14 => string 'layer' (length=5)
          15 => string 'link' (length=4)
          16 => string 'meta' (length=4)
          17 => string 'name' (length=4)
          18 => string 'object' (length=6)
          19 => string 'script' (length=6)
          20 => string 'style' (length=5)
          21 => string 'title' (length=5)
          22 => string 'xml' (length=3)
      public 'attrBlacklist' => 
        array (size=100)
          0 => string 'action' (length=6)
          1 => string 'background' (length=10)
          2 => string 'codebase' (length=8)
          3 => string 'dynsrc' (length=6)
          4 => string 'formaction' (length=10)
          5 => string 'lowsrc' (length=6)
      private 'blockedChars' => 
        array (size=100)
          0 => string '&tab;' (length=5)
          1 => string '&space;' (length=7)
          2 => string ':' (length=7)
          3 => string '&column;' (length=8)
  protected 'data' => 
    array (size=100)
      'view' => string 'challenge' (length=9)
      'id' => string '13' (length=2)
      'jform' => 
        array (size=100)
          'challenge_text' => string 'badgers' (length=7)
      'task' => string 'save' (length=4)
      '9652716f73e67f39fafd738fa7e859fa' => string '1' (length=1)
      'submit' => string 'Save this answer' (length=16)
      'Itemid' => string '5132' (length=4)
      'option' => string 'com_conlucra_game' (length=17)
However attempting to retrieve this with the usual

Code: Select all

$data = $this->input->get('data', array(), 'array');
is failing, as the second var_dump($data) shows this variable is null:

Code: Select all

/var/www/game.conlucra.com/public_html/components/com_conlucra_game/controllers/answer.php:73:null
Am I just missing the wood for the trees here ?

David

david0058
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 106
Joined: Wed Jan 20, 2016 10:58 pm

Re: Getting input in controller

Post by david0058 » Fri Oct 29, 2021 11:35 am

yeah, OK ... I got it.

I need to use the input to get the details in the data array, not the data array intself ...

$data = $this->input->post->get('jform', array(), 'array');

I'll leave the thread in case it helps anyone in future :-[


Locked

Return to “Joomla! 3.x Coding”