Hot answers tagged

11

The possible filters are: rules (Access Control Rules) unset (Do nothing, thus leaving the return value as null) raw (No filter) int_array (Filter the input as an array of integers) safehtml (Filter safe HTML) server_utc (Convert a date to UTC based on the server timezone offset) user_utc (Convert a date to UTC based on the user timezone offset) url (URL ...


7

Found what the issue is. I was using getInput function to show the field. $this->form->getInput('field2'); but showon attribute working only if I render the field using renderField function $this->form->renderField('field2'); Hope this helps someone facing the same issue


6

1. How to get Modules parameters inside Helper Function You are going all wrong with this. First, you can't use $this inside a static method, because they are independent of any instantiated object. Static methods can be called without instantiating an object so there is no $this reference inside. http://php.net/manual/en/language.oop5.static.php Just ...


6

I much prefer going for the OOP approach. This is what I use in one of my extensions. It's Ajax based so I have a separate function to get the parameters. helper.php: class ModSomethingHelper { private $params = null; public function __construct($title) { $this->params = $this->getParams($title); } public function ...


5

The more standard approach would probably be to use a plugin to catch the JForm object after the XML has been processed but before it has left the model to make your changes. An example of that function would be like this: function onContentPrepareForm($form, $data) { if (!($form instanceof JForm)) { $this->_subject->setError('...


5

Having looked at the JHtml radiolist function, it does not support custom classes. It manually adds the radio class via the actual core file. What I've done here is taken a copy of the core radio field, stripped a few things and modified it for your needs. Hope this helps: class JFormFieldContentRating extends JFormField { protected $type = '...


5

You need to load chosen plugin to style list box fields like this. Load chosen plugin first in your form layout file so that it can add style to your select boxes JHtml::_('formbehavior.chosen', 'select'); Add following class name to your form field (optional if you want to color it as mandatory field) class="chzn-color-state" To render the field on ...


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->...


4

In fact, it is very easy to filtering the list of users in User form field type. First in your manifest you should create a new type for your field, for example userFiltering (see below) <field name="myUser" type="userFiltering" label="LABEL" description="DESCRIPTION" /> In the fieldset of the manifest, add the ...


4

You could simply use <field name="modified_user_id" type="user" label="JGLOBAL_FIELD_MODIFIED_BY_LABEL" desc="A_DESCRIPTION_IS_ALWAYS_GOOD"/> It creates a modal field that display a list of users that you can filter by group by selecting the combo box on the top right of the modal window. If you need a simple combo box and you don't mind ...


4

Try to add an additional path where to look for forms before your call to $model->get('Form'). JForm::addFormPath(YOUR_COMPONENT_FORMS_PATH); You will need it because getForm calls loadForm (declared on the ancestor class JModelForm) which, before getting the form instance, uses this JForm::addFormPath(JPATH_COMPONENT . '/models/forms'); JForm::...


4

Initially I figured the best would be to use the controller method save(), which I finally got working like this: $path = JPATH_ADMINISTRATOR . '/components/com_anycomponent; JLoader::register('AnycomponentControllerAnyController', $path . '/controllers/anycontroller.php'); $controller = AnycomponentControllerAnyController::getInstance('Anycomponent'); $...


4

It seems that you actually have to specify what the path is for and put it in the right place, lol! The problem was in specifying a path for the fields instead of for the rules! This correction fixed the problem: <form> <fields name="params" addrulepath="/administrator/components/com_mycomponent/models/rules">


4

My first offering, so please don't shoot me. I've been fighting this one for a while and FINALLY found a solution that works well. Hoping to help others avoid this nightmare. The key piece I was missing is that the jform was submitting the checkboxes field as an array (duh) so accessing jform['whatever'] did not give the expected results. The OP said: ...


4

Both cited articles refer to Joomla content manager. Even though Flexicontent extends, onContentPrepareForm is not being called or rendered in your Flexicontent configuration. I suggest to test the plugin in a plain Joomla with a simple article. Once it works as expected. Try to enable it in Flexicontent. Concerning to "$this", it always refers to the ...


4

I was working with jForm and methods setField() and getFieldset() to set and retrieve the fields, but Joomla was throwing errors. While trying to add a list Joomla was unable to parse the XML until I added option_on="Yes" and option_off="Yes". (I'm not sure what/why these are necessary, but with them, the below code works). models\myform.php public ...


4

You will need to create a custom form field for this. So firstly, change the type of the field in your XML like so: <field name="brands" type="brands" label="Foreign Brands" /> Then in your XML, replace your <fieldset> with: <fieldset addfieldpath="/modules/mod_mymodule/fields"> Then, create a new PHP file called brands.php in: ...


4

Though the XML file and the rendered HTML both call them attributes, there is not a direct pass through of values. Hence, only some attributes make it to the HTML (and some extra attributes are added). All of this is based on the class that you can see here: https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/form/fields/text.php#L163 So for ...


4

I manged to get a solution as below. <field name="gralev_code][]" type="text" class="width20" label="JSCH_GRALEV_CODE" /> in model.php $formdata = $this->_jinput->get('jform', '', 'array'); $vals = $formdata['gralev_code'];


4

Well fortunately, I got my server side validation working by this way: use Joomla\Registry\Registry; JFormHelper::loadRuleClass('email'); class JFormRuleValidemail extends JFormRuleEmail { public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, JForm $form = null) { $emails = array($value); if (...


4

In your model class you want to override the getItem method like so: public function getItem() { $item = parent::getItem(); $item->second_table = $this->getSecondTable($item->second_table_foreign_key); $item->third_table = $this->getThirdTable($item->third_table_foreign_key); return $item; } The key here is you still call ...


4

I've been using FieldsAttach for this sort of thing, for a few years, the the concepts are clean and eloquent. Brian Teeman explains it well from an integrator point of view in his talk at https://www.youtube.com/watch?v=f2WLKWbRj5U but in some ways it is even more compelling from a developer's perspective. However, after watching Marco Ding's Joomla Day UK ...


4

Your main module file and template file will have $params variable created by Joomla! core. If you have static methods, then pass that variable to function call: class ModTestHelper { public static function getFoo ($params) { return $notthis; // whatever your return } } $result = ModTestHelper::getFoo($params); But if you want to use OOP:...


4

Edited to add subform field type-specific answer: Having looked at it properly, attaching your own layout to the subform field type is super-easy. Create a layouts folder in the same parent component folder (site or admin) as the XML file, and put your layout in it: -com_myComponent - controllers - layouts - mylayout.php - models ...


3

You can do it either in your Table class or Model class: // Convert a JSON field to an array $registry = new JRegistry; $registry->loadString($item->jsonfield); $item->jsonfield = $registry->toArray(); See the reference And vice versa: // Convert an array field to a JSON if (isset($data['jsonfield']) && is_array($data['jsonfield'])) { ...


3

You need both PHP functions to do this work: json_encode : http://www.php.net/manual/de/function.json-encode.php json_decode: http://www.php.net/manual/de/function.json-decode.php Maybe something like this: <?php $arr = array (); $arr[name] = $this->form->getInput('name'); $arr[name2] = $this->form->getInput('name2'); echo ...


3

Seems to me you want to save all the results as an array, and then save that array as JSON in a single field. Example of field.. look at your database, #__content table, see the attribs field for example of how joomla stores multiple pieces of info in one field as JSON Then just look at how the com_content models and controller work for some reverse ...


3

Add the message attribute, but better like this: <field name="my_code" type="text" size="15" label="My Code" validate="myrule" message="Field may only contain A-z or 0-9" /> :)


3

Yes you can do this. We have a component that has a concept of "Plans", it uses the same view for different access levels, but makes the fields accessible or not depending on the users groups. So for those uses that can "Run" a plan but not edit it, we turn "off" a bunch of fields. Depending on the field type this may mean setting several field attributes, ...


3

When using the above command to retrieve server request data, the form fields are organized in a key/value array. Which fieldset is irrelevant to retrieving the data from the array, simply use the form field name given in the XML form definition file. So, if you had a field called 'first_name' you would access like so regardless of which fieldset: $data = ...


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