How to add AJAX code inside a Joomla article by using a third party module like Flexi Custom Code?
I have a form inside my article and want to make a submit for this form without refreshing the page.
I read some pages talking about this, but I did not understand how to.
We have written an exhaustive and easy to use guide on how to use Ajax in Joomla. You can find it here.
In short, you will need to create a function ending by "Ajax" in the module in question that will check for the submitted information and that will return an output according to the submitted information. A valid function name can be funcAjax. Just make sure you pass "func" as the "method" in the ajax URL call.
You can use free extension like sourcerer Using this plugin, you can very easily insert html and javascript codes inside article.
here is a video tutorial on how to use it. https://www.youtube.com/watch?v=LiFa1Jq8igQ
Related
I have used separate solve.php because headers should be set before any echo statements.
program structure
Requirement: To view image on the same page when click view.
What I did: I coded already jQuery ajax method to do that. But the image is not shown. It just shows lengthy string on processor.php instead of image when ajax method is executed. I suspect that it is headers problem.
Even when I use jQuery ajax method, does not the new headers from solve.php are brought to processor.php? Cannot I use jQuery ajax method to achieve my requirement?
I already searched Google and SO. I found something about using a hidden iframe. But I do not know how to do that, where to put it how to set its src attrubute? Do I have to use it with together with jQuery? Please can sombody provide me that code segment and explain me in Simple English because I am a beginnner.
Or is there any other way to do my requirement?
My jQuery method, and PHP codes works correctly.
How can I send parameters like
radios=oneway&asal=CGK&tujuan=DPS&pergi=2013-12-31&pulang=&dewasa=1&anak=0&bayi=0
into an joomla article which injected by my custom php script with "sourcerer"?
In my case, I want to create an custom php article like search engine for example, and pass its parameter to other joomla article which customed by my custom php. Can anyone help me?
Why you are trying to pass parameters in url,
You already mentioned your first article is Custom PHP it send to another article that is also custom PHP.
So just use First custom PHP have some forms and second have some variables that recieves from first one.
you can simply access any article like below,
something like
index.php?option=com_content&view=article&id=69&catid=14&Itemid=471
set this as form action with second article Id and catId the submitting first one send data to the second article.
If you have any doubt in Include HTML or PHP codes into Joomla article ,
Hope this makes clear.
I am trying to do something really basic but can not seem to find a tutorial for it.
I have created a simple web form using HTML what I need todo is create a php file that will read the web form, open a new browser window (or display in same page) the contents of the web form, do toy guys have any tutorials on this?
Many thanks
Chris
I'm sure many will post different links to tutorials that they like, but I thought I would just give you the basic. The key parts to the form are the method and action. The Method attribute tells ths browser how to submit the data, either through GET or POST. The action attribute tells the browser where to submit the form. (In your case it will be, somepage.php) If you ever need the form to submit back to itself, you can here use explicitly type the page name or you can use use PHP to dynamically insert the page name. Finally, make sure that all your form fields use the name attribute, as this is how php will access the elements.
On the php side of things, your form variables will be stored in either $_GET or $_POST depending on how on method you used to submit your form. For example, assume you have a input element of type text with the name 'FirstName'. Within php you can access this by doing
<?php
var firstName = $_GET['FirstName'];
?>
This should be enough to get you started. Be sure to check out the php docs and the other tutorials listed on this page for a more details.
Please look at this tutorial: http://www.learnphp-tutorial.com/HtmlForms.cfm
And you can find many more tutorials if you search it on Google.
This should help : http://www.php-mysql-tutorial.com/wikis/php-tutorial/php-forms.aspx
Context
I'm working on a project that I'd like to make more dynamic with PHP + AJAX.
I'm using jQuery for the AJAX part because I totally suck in Javascript, and anyway it seems to be worth something.
I reached a point where my application needs to use a form to send a post, and I want to use an ajax call to perform this action. In the page I'd like to send the post, there is also a list of the most recent 15 posts submitted.
First question: Should I just forget about it and use just PHP?
The action
The user writes something in the <textarea></textarea> and clicks on a <a id="myPostSubmit">Submit</a> that is the handler that I'll manage on the jQuery script with something like $("#myPostSubmit").live('click', function() { /* here i make the ajax call */ });. If the post is successfully submitted we are going to do something (I'll talk about it in the next section), either we will alert the user using my showAlert(text) function, that shows a black box for 4 seconds with the text in it.
Second question: Should I manage the click event in any other ways? Should I create a function, such as sendpost(post) and attach it into the HTML onclick="" event?
If the post is successfully sent
I'd open a discussion about 2 options:
We refresh the page [not actually
loading the entire page but making
another ajax call that retrieves the
posts lists and makes disappear the
old one, load the PHP file to
retrieve the new posts (including
the one we just sent), and then make
the post list appear]. Pro: 1) We are sure that what the user is reading after the post list is loaded is the real post sent. So it actually double checks the action. 2) We load also some possible posts sent in the mean while. Cons: 1) We have to create a PHP file that gets the post list template, slicing the template of that page in 2 files. 2) It doesn't really seems that smooth to me.
We just use Javascript to get the post template, add it to the list. Pro: 1) We make it really smooth, without reloading the entire page. 2) We don't need of any PHP file to reload the page. We just use Javascript (jQuery). Cons: 1) How do we get the post html template to add it to the list? 2) How do we get the user (logged) informations without PHP?
Third question: Is it better the 1st or the 2nd solution? Would you provide a even better 3rd solution?
The PHP page
The PHP page that will receive this AJAX call is : ?p=action&a=sendpost. The page require $_POST['myMessage'] to be set and not empty and nothing else. The page itself will get all the user infos from the cookies and will manage to perform the needed query.
The application
It is divided in 3 parts: App, Template, Library. Basically each page of the application has its own .app.php and .tpl.php file.
The .app.php file manages the building
of the basis of the page, using classes
and other stuff from the library. In
our case it retrieves datas from the
database and put them into
variable.
The Template is called at the end of the .app.php file. The .app.php file send to the template the retrieved data and the .tpl.php file outputs them.
The library is used to contain the classes and functions we need in the application file.
Fourth question: Is this a good way of manage my web application?
Edit: What about returning the alert message to the user?
I read about an option, inside $.ajax() that will manage the response on success or in error. The documentation about it is very simple and I didn't get it.
Fifth question: How should I return (from the PHP file) the error
or the success?
First question: Should i just forget about it and use just PHP?
Well, you application will relay on JavaScript if you use ajax, this days i think it just fine ;)
Second question: Should i manage the click event in any other ways? Should i create a function, such as sendpost(post) and attach it into the HTML onclick="" event?
Create a function and bind onclick. Code will be more readable ;)
Third question: Is it better the 1st or the 2nd solution? Would you provide a even better 3rd solution?
My solution: ajax submit the form and on callback insert new comment in to the list or display error message if user can't comment.
Check jQuery serilize() for submitting forms data with ajax.
Fourth question: Is this a good way of manage my web application?
It's just fine ;) When you application get's bigger you will have to redesign it, but don't do it know, do it when current solution becomes to hard to work with.
Read some good book on building MVC framework. And on programming patterns in general.
You seem to be on the right track with everything. There are lot of opinions called "best practices" about how to exactly attach event handlers, how to reload the data on the page and how to organize your application, etc, but I personally would rather build more software instead of worrying about details like that. The details will come to you eventually.
I personally find that updating whole chunks of server-side-rendered HTML on the page is more robust solution, but I have seen people getting excellent results with templates.
there are two templates i am using for view and edit(is having the form to update),
the view will contain edit(link or button), on clicking the edit button i want that the edit template should be loaded (using Ajax, without refreshing the page).
and after editing it should be redirected to view again (using ajax same as above).
is there any code or method to do that? please help me...
You can replace your whole content DIV with the result of the AJAX call. In the controller, check if the request is a XMLHTTP request. If so, only return the template without the layout around it.
So you don't change the template, you are just fetching the result of an action via AJAX.
Hava a look the documentation integrating AJAX.
You should also consider in-place editing if it'll fit into your design.
I think in-place-edit is best option here. I have used jeditable and jQuery in symfony to achieve similar functionality. Please have a look at http://myimalert.com/stock_alerts
I could not find native support for in-place-edit in Symfony 1.4.