Small module. How?

procajlok

Member
Hello!
If you can tell me how to make such a module I will be grateful. Well... i want create small module where i have textfield and two buttons. Textfield is for quote (max 200 char.). First button save quote to table in DB. Second button (basically there i have problem) show in dialog box random quote from DB.
How should I configure the second button to display what I want?

Regards! :)
 
OK - another question. How i can show random value from SELECT query in Java dialogbox (alert) after click button in form?
 
So your random 'quote' comes from the list the form is on?

You can load a random record in a form or details view by using rowid=-2.

And you could open a Fabrik popup from a button by using this Javascript (in the Javascript tab of the button element, onclick)

Code:
Fabrik.getWindow({
   id: 'some-unique-id',
   contentURL: 'index.php?option=com_fabrik&view=details&formid=123&rowid=-2&tmpl=component&ajax=1&format=partial',
   loadMethod: 'xhr',
   title: 'some title'
});

Change 123 for your form ID.

You might have to use some custom CSS or a custom template to hide everything except the text.

You can also size the popup.

But let me know if that approach works for you, then we can work on styling it nicely.

-- hugh
 
OK - thanks. But maybe we'll complicate the topic a bit ;)
Well, every quote have status (checkbox selected by the administrator - "active" = 1). I would like to draw a random record from those that have status 1. Any chance to implement this condition to content URL?
 
If you only need the list for adding quotes or selecting the active ones you can add a prefilter to the list.
If the admin should see all records set the appropriate prefilter access level (if you have something like "nonadmin") or add a 2nd prefilter
OR id > 0 , applied to "admin" (or whatever access levels you have defined).

Or you can copy the list, set the prefilter and use this list in your module.
 
Nice! It works fine, but in implementation its soo complicated. In more advanced projects it would be great, but in this project I would need something lighter than this modal box... :rolleyes: Any other possibilities ?
 
The only other possibility is to roll your own AJAX call, using the "user AJAX" method. See ./components/com_fabrik/user_ajax_example.php.

The comments in there are a bit old, I'd recommend using jQuery.ajax() rather than the Mootools Request. But the principle is the same. Some JS on the button element that calls the &task=plugin.userAjax URL, a method in your user_ajax.php that gets a random record and returns the quote text, which is then displayed in a .done() handler on the AJAX call in the JS.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top