Hot answers tagged

31

$app = JFactory::getApplication(); $postData = $app->input->post; Is the way to go, you will get a JInput object and can use it like JRequest $var = $postData->get('varname', 'defaultvalue', 'filter'); The filter could be 'int', 'cmd' or many others - the complete list can be found in this function: https://github.com/joomla/joomla-cms/blob/...


16

In addition to @Bakual's answer, let's assume you a simple form like so: <form name="upload" method="post" enctype="multipart/form-data"> <input type="file" name="file_upload"> </form> To upload the file once the submit button has been pressed, you can use this: $input = JFactory::getApplication()->input; $file = $input->files-...


11

In a proper MVC structure, only your controller should interface with your request data, in this case JInput, and the dependencies injected into the view and model when instantiated within the controller. With the current CMS structure, all three pieces of the MVC structure are often interfacing with the request data. In models, this is usually done in the ...


8

OK, so let us look at what options are available. The examples below are using JInput and have been tested in Joomla 3.3. I am POSTing the following data at Joomla: stuff[abc]=1 stuff[def]=75 stuff[123]=<script src="http://imanaughtysite.com/muahahaha.js"/> I want to get a clean array of integers, so the expected result is: $expectedResult = array(...


7

There are two tricky things people usually fall over when it comes to file uploads using JInput: Your form tag needs to contain enctype="multipart/form-data" The file array is retrieved with $input->files->get('upload');


7

Joomla does not support multiple type as filters. This can not be done either using JRequest or JInput. There is no workaround available in Joomla till now. You need to handle multiple filters in your code only.


7

Please check this code - $jinput = JFactory::getApplication()->input; $ip = $jinput->server->get('REMOTE_ADDR', '', ''); //Here default value and filter are null, so you can write $ip = $jinput->server->get('REMOTE_ADDR'); By this you can get the ip address.


6

TL;DR: there is no equivalent, because it's not needed. JInput data is by default a reference to $_REQUEST, so it dosen't have own unset method, because it is not needed. Although it would be nice to have $input->unset('variable1'); for completness of API. You should use plain PHP, e.g unset($_REQUEST['variable1']);. If you have your variable in $_GET, ...


5

The first method looks for elements that start with the name that you have specified: <input type="hidden" name="nameOfArray[test][1]" value="test" /> <input type="hidden" name="nameOfArray[]" value="test" /> <input type="hidden" name="nameOfArray[test][]" value="test" /> <input type="hidden" name="nameOfArray[tester][yes]" value="test" ...


5

Source of foo are the PHP superglobals such as $_POST or $_GET. So it's data what the user submits via a form, URL or cookie to your component. So you are receiving in a safe way a parameter that was sent to you via a HTTP method. This: $myVar = $app->input->get('foo',0,'int'); is largely equivalent to: $myVar = (int) $_REQUEST['foo']; You should ...


5

You may want to have a look at the cookie authentication plugin. It sets and reads a persistent cookie. It's found here: https://github.com/joomla/joomla-cms/tree/staging/plugins/authentication/cookie To read a cookie, you can use $app = JFactory::getApplication(); $cookieValue = $app->input->cookie->get($cookieName); To set a cookie, you use $...


5

Joomla! dosen't support style attribute on text field or sending it with getInput method. I expect you know where similar_text field is defined in XML. If you don't then they are usually in /components/COMPONENT_NAME/models/forms for components. For modules, they are in general .xml file. You should add class attribute to that field. XML <field ...


5

This should work: $values = $app->input->getArray(array('data'=>'array')); echo $values['data']['server']; Please see I did not mention post variable specifically, because this can retrieve both get and post values. If you need to get a value from a specific super global, such as post, you can use something like $app->input->post You can ...


5

Yes, you can get the form values without jform. Following is the approach: $data = $jinput->post : returns all post data $something = $jinput->post->get('something', 'default_value', 'filter'); Refer here: https://docs.joomla.org/Retrieving_request_data_using_JInput#Getting_Values_from_a_Specific_Super_Global $data = $jinput->post->...


5

1) JHtml is an alias for Joomla\CMS\HTML\HTMLHelper class. You'll have to start using the real class sooner or later because the alias will not exist in Joomla! 5.0. To use the real class you have to either import it: use Joomla\CMS\HTML\HTMLHelper; HTMLHelper::doSomething(); HTMLHelper::doSomethingElse(); Or use fully qualified class name: \Joomla\CMS\...


4

You're definitely not missing something. If you find that you're doing this regularly, you can create a system plugin to extend the existing JRequest class and add a new filter type to that.


4

One error is $src = $file['tmp_name'];. $file isn't defined. You're should use $file1 there. Another thing is that JFile is one of the classes which don't autoload for some reason. So you need to either register it in the autoloader or require_once it. I would do something similar to what Lodder suggested for the actual uploading part: JLoader::register('...


4

You could try: $data = $input->post->get('data', array(), 'ARRAY'); $server = $data['server']; Haven't a playground to test this in, but I think it works.


4

Yes, you can achieve this by using JInput. <?php $app = JFactory::getApplication(); $input = $app->input; $jform = $input->get('jform', array(), 'ARRAY'); print_r($jform); //$jform will show all the data of your form ?> Please refer this document for more details: https://docs.joomla.org/Retrieving_request_data_using_JInput


3

Try this: $app = JFactory::getApplication(); $jinput = $app->input; $filter = $jinput->getVar('filter',array()); Hope it works for you


3

It seems another way to accomplish this is simply pass an empty array: $app = JFactory::getApplication(); $postData = $app->input->getArray(array()); This will retrieve everything in the JInput data var as if you were accessing the $_REQUEST super. This does not work in the Joomla! 2.5.x version of JInput though.


3

I misread or misunderstood the documentation of $jinput->getArray(). I understood this to return a subset of the input variables, as specified in an array of the variables you're interested in. While this may be true, it will also return all input variable if an empty array is supplied: $allfields = $jinput->getArray(array())


2

I'm of the strong belief that it should be retrieved where appropriate. That is to say you should always use JInput otherwise you're duplicating data and potentially breaking DRY principles. A view class should be retrieving data to populate the the view's templates (/tmpl files) or layouts from the model, not injecting values into the model. A view after ...


2

Try using something like the following: $input = JFactory::getApplication()->input; $cookie = $input->cookie; $post = $input->post; $cookie->set('destinationcookie', $post->get('destination'), strtotime( '+90 days' )); $destination = isset($post->get('destination')) ? $post->get('destination') : $cookie->get($name = '...


2

Last time I did some research on this area (March 2013), I found this solution, which is not using JInput: I've inspected how JFactory calls JSession but I haven't found a way to set the expiration when storing data. Inside a system plugin, using the method onAfterRender() $cookie = session_get_cookie_params(); $cookie['lifetime'] = DESIRED ...


2

A couple of things. First, verify this is a bug by using the deprecated but still working JRequest to get the file data. I've had to resort to using this method myself recently for a file upload need. $file = JRequest::getVar('file_upload', null, 'files', 'array'); If that doesn't work still, simply try dumping the $_FILES['file_upload'] request ...


2

To set something on Joomla 1.5, you will need to use setVar, like so: $template = JRequest::getVar('template'); JRequest::setVar('template', $template); Disclaimer: Joomla 1.5 is extremely old and is not officially supported anymore. You will also find people on here less willing to support you. Please consider migrating your website to the latest version ...


2

Inside the display method of your view class put this line before parent::display($tpl);: $this->get('State')->filter = array('Foo'=>'Bar'); I always use this line to filter featured items in my components and it works: $this->get('State')->{'filter.featured'} = 1; Hope it helps.


2

Just been messing around with this a little. Try adding a blank default value and filter type as arguments, like so: $test2 = $jinput->get('filter', '', 'RAW');


2

You must find an solution to bind the Data from input to the TableObject, thats all. $dataToStore=array('creationdate'=> $input->get('creationdate')); $row = JTable::getInstance('Item','BestiaTable'); // BIND DATA TO THE TABLE OBJECT!!! $row->bind($dataToStore); $row->check(); // please write an check method which checks the datas before ...


Only top voted, non community-wiki answers of a minimum length are eligible