Form in Joomla website to run script - joomla

I'm new to Joomla and quite newbie to websites in general.
I want to provide the user a form with a couple of text-input widgets and some check-buttons. After the user fill them and hit the "Submit" button I want to run a (python) script in the background. The script will collect some data from the internet and make a specific plot. The plot is embebed in a HTML document (I'm using Bokeh here), which I should present back to the user.
And I need some help to figure out how to do it.
Doubt number 1: I saw that there are some Form extensions around (e.g, Form Maker), but do I need them?
Doubt number 2: How do I trigger the execution of a (python) script on my system, wait for its return and access the output (let's say output is called 'plot.html')
Doubt number 3: The output (plot.html), should I present it on a new tab of the user's client or may I embed at this point in the page where the form is (below the form, for example)?
Thank you

You could start by creating a small Joomla module. In its tmpl/default.php file, just create the form in HTML as you would with any other form - have the form submit to itself.
In the module's entry point mod_mymodule.php, use a conditional to check the form has been submitted, then use one of PHP's program executions functions, such as exec, to run your Python code, passing in the needed variables.
Finally display the your output HTML in tmpl/default.php passing it as a variable in from mod_mymodule.php.

Related

How we call "Pages" name in Dropdown in Signup form of PHPfox?

In PHPfox, i want to call "Pages" name in drop-down in Signup form. Reason for calling "Pages", Actually i have created many pages for college name & that are saved in database. So if someone comes for signup, i want to show them college name in drop-down (which are basically "Pages").
Please help me.
Thanks in advance.
You will need 2 plugins, one to show the HTML and one to process what to do with the user input:
1) Make a plugin that fetches the pages, maybe the hook user.component_controller_register_1 or another in that controller would do but otherwise you can always use a low level hook like run_start and check if its the section where you want it.
To show the HTML you have 2 options: include a JS file to populate the sign up form with anything that you want, or if you have a custom template you can just assign the array to the template variable and look through it in your template.
2) Once the html part is showing and working make a plugin for the sign up routine, I think the hook user.service_process_add_1 should be enough given its location.
Dont forget that the input name for the signup is an array, so your drop down needs to look somewhat like this:
<select name="val[my_dropdown]">

How can I preview Virtuemart2 Order verification email layout changes?

I am trying to change the layout ( css/html structure) of Virtuemart 2 order verification emails. Problem is that I have to make a fake purchase each and every time I do a change in the 10 different files (located # components/com_virtuemart/views/invoice/order/tmpl) that create this email template.
The closest "preview" I got was this direct access url "http://domain.com/index.php?option=com_virtuemart&view=invoice&layout=invoice&format=html&tmpl=component&virtuemart_order_id=1401"
But again it loads Joomla's head/body elements not the actual email template.
So how can I have a "preview" of how the template looks like with my new changes BEFORE make an actual test purchase? Is this possible?
You shouldn't change the core files otherwise the next update of VirtueMart (of which there are many) will erase your changes.
You should use Joomla!'s template overrides which VM2 supports that way you can update as needed to new versions without loosing your changes. See this article on docs.joomla.org on "How to override the output from the Joomla! core" and this one on template overrides.
3. You need to add the &format=raw at the end of the link to retrieve just the output of the component with out the template/html body wrapped around it. Of course that relies on the component as well.
I was going to suggest using raw, but looking at the current VM2 it doesn't properly support the format=raw option. Looking at the mail layout in the invoice view it not structured to return it the way you expect, it actually generates a HTML version by default with a matching text only version.
The best I could come up given those two options
Return a close equivalent of the HTML email
http://domain.com/index.php?option=com_virtuemart&view=invoice&layout=mail&virtuemart_order_id=1401&tmpl=component
Return the text version, albeit wrapped in the html page... you may have to view the source to see your invoice text.
http://shop.craigphillips.biz/index.php?option=com_virtuemart&view=invoice&layout=mail_raw&virtuemart_order_id=4&tmpl=component

Saving wysiwyg Editor content with Ajax

I am writing a cms (on .net) and have structured the whole page to work client side.
There is a treeview that lets you add/remove/move items and define their names in the languages defined. For each language I save the names of the category defined, but when there is HTML content associated with it, i fall into the JavaScript serializer problem that finds the content too long to be serialized.
What would be the best approach to make sth like this work. Shall I change everything to work with postbacks, or try to manually call _doPostBack for the editor content (which I don't want). Thank you in advance.
I guess would be great to make auto-save with time interval which will submit only diffs between current state and previous save. It will do the key if the user will edit it manually, not for copy/paste, of course. It is if we talk about really big data that we need to save.
Otherwise need to find some ways to compress the data before submitting: json+base64, etc.

Facebook Game Function, Optimizin a Call, and Loading Bar

I am attempting to make a Facebook game and trying to replicate a common function that I usually find in many other Facebook game (a call to my website and illusionary image that is a loading bar).
The function should do the following:
User clicks on Button
Animated Gif Appears (Loading Bar)
Button Update User's Status
Animated Gif Disappears
Facebook Canvas page is updated
The code I currently have can be found at <dead link>
I am having trouble thinking of Step 2 and 4.
I need to optimize Step 5.
To clarify what happens on Step 5. I have Box 1 which has my stats. And Box 2 which has my points. I click on Box 1. This should update Box 1 with 1 points, and update Box 2; minus a point. (Clicking on Box 1, concurrently update both boxes)
I have successfully done this, but it is quite slow. I was wondering if there are alternative way that may be faster than what I am currently doing.
Script Updated with Mark-up. <dead link>
I've found a quick way to optimize the call. Rather than querying for data that I already have query, I will be using the first query to grab most of my data rather than querying it when I update.
It would help greatly to see the document markup (XHTML) where you have your elements and the calls to your javascript functions.
For steps 2 and 4 I recommend using the visibility attribute rather than display, or having the loading bar in an fb:js-string and using elem.setInnerFbml when you begin loading and once you have your response data, simply update it to the new content (you don't need an explicit loading_finish function in this case).
In your get_skillpoint function, you set parameters in an object and then you specify the action parameter again in the URL you are posting to as a URL query param - you may end up with one value overwriting the other, depending on how you access these values on the server side. I would recommend using different names for these two parameters if they are not the same. Also, why are you trying to send separate GET and POST variable sets? You should put everything in the POST and simply leave out the URL query string. I vaguely remember losing data that way in the past (vaguely, mind you).
If you can post your markup I'll update my answer with any light it sheds on the problem. It might be slow simply because Facebook isn't blinding fast when it comes to FBJS and AJAX. Also, FBML being returned must be preprocessed in the FB proxy before your app gets it, which adds a bit of lag; it's a bit faster to return JSON and just pull the data needed out of it, then place the appropriate pieces into an existing element or make use of fb:js-string.

Reload the page without submitting it back to the server

the problem I have is that I have two sets of values in a drop down list. If type 'A' is selected I want a text box to be populated with a value from the database and be read only. If Type 'B' is selected the box is to be empty and editable.
My original code is written in jsp/struts and I have sort of achieved this by using
onchange="javascript:submit()" to reload the page, but this has the obvious drawback of saving any changes you have made which means you can't really cancel.
I also have other problems with the serverside validation due to this method.
Is there a way of making a jsp page reload on change, that way I could write javascript to change the way the page looks according to the values held in the session. That way the save/submit function will only be called when the page has properly been filled out and the server side validation will work as designed.
I know that this is something that AJAX is good at doing but I am trying to avoid it if possible.
AJAX is your only other option my friend, unless on the original page load you load all the other possible values of the Text Box so you don't need to go back to the database. Well, you could try putting the text box in an IFRAME, but you will probably run into more problems with that approach than just going with AJAX.
Without AJAX what you are asking is going to be difficult. Another option (which is ugly) is to write out all possible values for the second list box into a data structure like an array or dictionary.
Then write some javascript to get the values from the data structure when the user selects from the first list box. The amount of javascript you will have to write to get this done and to do it correctly in a cross browser way will be much more difficult than simply using AJAX.
Not sure why you'd try to avoid AJAX in today's world, the JS libraries out there today make it so simple it's crazy not to try it out.
I just had to replace a page that was written as Vincent pointed out. I assume at the time it made sense for the app, given the relative size of the data 4 years ago. Now that the app has scaled though, the page was taking upwards of 30 seconds to parse the data structures repeatedly (poorly written JS? maybe).
I replaced all the logic with a very simple AJAX call to a servlet that simply returns a JSON response of values for the 2nd drop down based on what was passed to it and the response is basically instant.
Good luck to ya.
One way is to change the form's action so that you submit the form to a different url than the "save" url. This lets you reload certain aspects of the form and return to the form itself, instead of committing the data.
<script>
function reload() {
document.forms[0].action="reloadFormData.jsp";
document.forms[0].submit();
}
</script>
<form action="saveData.jsp" method="post">
<select id="A" name="B" onchange="reload()"><!-- blah --></select>
<select id="B" name="B"><!-- blah B --></select>
<input type="submit">
</form>
If I understand you correctly, that you want either a dropdown (<select>) or a textfield (<input type="text">) depending on a choice (typically a checkbox or radiobuttons) somewhere above in a form?
I that case you may need to handle the two types of input differently on the server anyway, so why not have both the selectbox and textfield in the area of the form with different names and id and one of them hidden (display = none). Then toggle visibility when the choice changes. On the server you pick eiter the selectbox or textarea input (wich will both be present unless you disable (disabled="disabled") them too, wich I think is uneccesary) depending on the choice input.
Of course if you expect that the user usually just need the text-input, and a few times only, needing a massive list; it would be better to use ajax to retrieve the list. But if it's the other way around (you need the text-field only occationally), as I assumed above, it will be faster to have both present in the initial form.
If the drop down only contain easily generateable data, like years from now to houndreds of years back it could even be much faster (requiring less bandwidth on the server) to generate the data client side using a for loop in Javascript.
I know a taglib that can fit to your problem:
AjaxTags.
I use this taglib in my J2EE projects and it is very simple to integrate it into web applications.
This taglib give you several tags designed to execute AJAX request in your jsp files.
Here is the description of each tags: http://ajaxtags.sourceforge.net/usage.html
The tag which will help you is the ajax:select tag. It allows you to populate a select tag which depends on an other field without reloading the entire jsp page.
If you more informations about it, ask me and i'll try to answer quicky.
Along the lines of what Strindhaug said, but if you need dynamic data:
Could you have the backend write JS into the page, and then the JS would change the form as required? The backend could propagate some variables for descriptions and such, and then the JS could change/update the form accordingly. If you aren't familiar with this, libs like jQuery make things like this easier and more cross-browser than rolling-your-own (at least in my experience).
Aside:
If you're not using AJAX because it was hard to code (as I didn't for a while because my first experience was from scratch and wasn't pretty), as others have said, libs like MooTools and such make it really easy now. Also, there is not shame in using AJAX properly. It has a bad rap because people do stupid things with it, but if you can't simply write premade values into the form or you have to do live look ups, this is one of AJAX's proper uses.

Resources