Where to put a simple callable php script in Joomla directory - joomla

I have some Joomla HTML content which contains a simple HTML form which results should available to a simple PHP script.
Basically the HTML form looks like:
<form action="action.php" method="post">
The question is where can/should I put my action.php script in the Joomla project directory to be
callable for my form action and
not overwritten by Joomla updates

I would recommend creating a component for forms. You probably need to handle the input in your form, and do some action based on what is in the form, and return the form if there are errors, etc.
Simplest way to make a component:
add a folder in components: /components/com_whatever
Add php-file: whatever.php in folder com_whatever
Add xml-file: whatever.xml
Content of whatever.xml:
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2.0" method="upgrade">
<name>Whatever</name>
<version>1.0.0.0</version>
<files folder="site">
<filename>whatever.php</filename>
</files>
<administration>
</administration>
</extension>
Content of whatever.php:
<?php
defined('_JEXEC') or die;
echo "HELLOOOO";
// or rather some code handling your form data
Install the component by going to yoursite/administrator/index.php?option=com_installer&view=discover
Now you can reach whatever.php from the form, using:
<form action="index.php?option=com_whatever" method="post">
There is lots of stuff you can and probably should do in your component, but this is the bare minimum.
PS: You could install a form component, there are lots. Alternatively you could use a component-builder to create your form, then you also get admin-tools to handle the incoming data.

For that you have to create joomla content plugins, using content plugin you can handle form submit action.
For Reference:
https://docs.joomla.org/J3.x:Creating_a_content_plugin

Related

How not to be confined into content area... full size web app on Joomla

I am currently creating an Intranet ERP application that will integrate an already existing corporate Joomla 3.1 based web site.
The extension i made so far only has one default controller php file and everything is made using a JavaScript UI framework. (i.e. jqWidgets) So i am not using model, views, helpers.
The other php files are there to respond to the client side interface AJAX requests.
So i mainly need Joomla for the user authentication and session control features but i dont want it to confine my extensions output to the content area... i need the entire document surface... no menu, no module columns, no nothing !
Can it be done ?
Two ways
component.php in the template will show only the component's output add &tmpl=component to your urls
Make a custom template that only outputs the component
<html>
<head>
<!-- put what scripts stylesheets you need etc//-->
</head>
<body>
<jdoc:include type="component" />
</body>
</html>

Joomla. Where article is outputed?

I'm new in Joomla and so need some help with basic.
I have write template for Joomla 1.7 and use it in such way:
Template have one position called "main".
I use custom HTML for building page structure and include modules with ModulesAnywhere plugin.
Now I have module which list all articles from category. When I click on the link I am redirecting to my_site/category/article_name. But where article text is outputed?
It seems like that it should be ouptuted in position. If so how could I dynamicly add this tag in my custom HTML?
The articles are showed by default (or any other component content)where this tag is located in your template:
<jdoc:include type="component" />
Normal content does not require any position like modules.

Joomla 1.5 jdoc include type head works only on homepage?

I have a problem withjdoc include head. On any other page than Home, the <jdoc:include type="head" /> result is not complete, it does not include jQuery library etc. but only the title and favicon. Any idea how could I keep the JS libraries and all from jdoc head on all pages, not just the homepage ? I don't know why they get loaded on home but not on login for example, or search...
Thanks.
By default header in Joomla doesn't contain jQuery... It loads Mootools.
If you need to load jQuery you have to use a plugin like this one.

Joomla - Insert .js and .css files into a single Joomla article?

Is it possible for a single page on a Joomla website to include it's own custom .js and .css files?
I basically would like to add two custom javascript and css files for a particular page. I don't want these files included into any other Joomla pages.
Any suggestions would be appreciated.
Thank you
Try using a custom code extension such as JUMI. It is designed exactly for this purpose.
From the description: With Jumi you can include php, html, javascript scripts into the modules position, articles, category or section descriptions, or into your own custom made component pages.
The solution from Soygul wont result in proper HTML since these statements / includes belong to the HTML header.
Use : http://extensions.joomla.org/extensions/edition/custom-code-in-modules/11936
This plugin allows inserting material into the head section of your Joomla web site.
You can then use the menu assignment functionality to just add that to certain pages.
Its quite easy to write a simple module like that for yourself - but since this seems already available go with that one. If it doesn't fit your needs :
You just need an "empty / hello world" module with these two statements :
( http://docs.joomla.org/Creating_a_Hello_World_Module_for_Joomla_1.5 )
( http://docs.joomla.org/Adding_JavaScript_and_CSS_to_the_page )
// Add a reference to a Javascript file
// The default path is 'media/system/js/'
JHTML::script($filename, $path, $mootools);
// Add a reference to a CSS file
// The default path is 'media/system/css/'
JHTML::stylesheet($filename, $path);
I'm not a big fan of adding new extensions to Joomla unless absolutely necessary. If you do, make sure it's not on Joomla's list of vulnerable extensions, first. Each third-party extension/plugin you add is just one more potential back door for hackers.
To add your own custom CSS for a page, you can either edit your template's master CSS file, or just create your own and link it to the project. Here's how you'd do that:
First, figure out how your CSS files are being called. The actual file names will surely differ from my example, based upon the template you're using, but let's look at the Joomla SYSTEM template, which is located in templates/system. The index.php file controls everything, so open it up and you'll find this line:
<?php
include dirname(__FILE__).DIRECTORY_SEPARATOR.'component.php';
?>
Open component.php and you'll see some code that looks like this:
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
You can see the call to include a CSS file in the 3rd line. All you need to do is add another line calling a CSS file you create. Create a new file called /templates/system/css/custom.css (or whatever you like) and rewrite the code segment in component.php to look like this:
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/custom.css" type="text/css" />
Now you can just code out your own CSS in the new custom.css file you created. You can do this with any template system from RocketTheme or YooTheme just as easily. In fact, if you use one of their templates, they probably already have a custom.css file that you can simply add your own code to. Just be aware if you do it that way and then later update the template, you'll lose your code additions. That's why I prefer writing my own file. You can probably do something very similar to include custom JS code, but I tend to avoid JS like the plague, so someone else will have to address how to link out to a custom JS file.

redirect to a particular page after contact form is submitted in Magento

how can i re-direct to a particular page after the user submits the contact form in Magento? form.phtml has
<form action="<?php echo Mage::getUrl(); ?>contacts/index/post/" id="contactForm" method="post">
but i'm not sure where to find the php file that controls the email sending and redirects. any ideas? thanks
EDIT: found this in IndexController.php under app > code > core > Mage > Contacts > controllers
$this->_redirect('*/*/');
I know its answered, just sharing my experience.
I had made a contact form through a CMS page. The form worked fine. But after submitting it, it would redirect to the magento contact form. To redirect it back to CMS page, i had to put
$this->_redirect('contactus');
where contactus is the URL identifier.
Also after redirect, the success / error message would not show up. For that i had to make changes here.
Go to
/app/design/frontend/default/yourstore/template/contacts/form.phtml
<div id="messages_product_view">
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
</div>
with:
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
I got the solution from here
For the next person
go to silk software and create a new module using their module creator
http://www.silksoftware.com/magento-module-creator/
Enter your company name and module name
Then change "Need Rewrite Magento Class" to Yes
click "Add Class" the class name will be Mage_Contacts_IndexController
This will create a module with everything you need
Add the postAction method from the Core Controller to your newly created controller
Then change the redirect to redirectReferer() at the end of the postAction method
The module creator will create everything you need to overload the Contacts Controller and save you time from troubleshooting typos. Also, save yourself the trouble down the road of editing the core files directly.
DO NOT EDIT THE CORE FILES!
Could also just create custom url redirect.
id path - contacts/index
request path - contacts/index
target path - 'redirect url'
To avoid overwriting core files and harm update compatibility, I overloaded the controller as described here: Tutorial: Overload a controller
<frontend>
<routers>
<contacts>
<args>
<modules>
<My_Module_Contacts before="Mage_Contacts">My_Module_Contacts</My_Module_Contacts>
</modules>
</args>
</contacts>
</routers>
</frontend>
And rewrote $this->_redirect('*/*/') to $this->_redirectReferer('contacts/index'), so you get redirected to the previous page, and if no referer was set, to /contacts/index as a fallback.
Also I changed form.phtml from
<div id="messages_product_view">
<?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>
</div>
to
<div id="messages_product_view">
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
<?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>
</div>
to display the error messages.
IndexController.php under app > code > core > Mage > Contacts > controllers
changed
$this->_redirect('*/*/');
to
$this->_redirect('');
and it re-directs to the homepage now.
From my experience, I suppose change the success message after from submitting the contacts page.
I used the below code in my static page
{{block type='core/template' name='contactForm' form_action='mywebsiteurl/contacts/index/post' template='contacts/form.phtml'}}
I override the default controller action in my custom module config.xml file.
<routers>
<airhotels>
<args>
<modules>
<apptha_airhotels before="Mage_Contacts">Apptha_Airhotels</apptha_airhotels>
</modules>
</args>
</airhotels>
</routers>
And in my custom controller(Apptha_Airhotels_ContactsController) action (postAction ) I used my custom message and redirect to custom url.
Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
$this->_redirect($formUrl);
This form url is defined as :
$formUrl = basename($this->_getRefererUrl());
A pretty dirty but easy approach is to redirect /contact/index to /contact after form submission.
Say you extend the Magento Contact in your template like here:
Add file Magento_Contact/templates/form-submitted.phtml with the following content:
<?php
header('Location: /contact');
exit;
Then change Magento_Contact/layout/contact_index_index.html to use that template as below:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Contact</title>
</head>
<body>
<referenceContainer name="content">
<block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form-submitted.phtml">
<container name="form.additional.info" label="Form Additional Info"/>
</block>
</referenceContainer>
</body>
</page>
Everything works, including the flash message.
Voila!
The combined solution is given in both answers from #Simon and the others
change $this->_redirect('*/*/') everywhere in app/code/core/Mage/Contacts/controllers/IndexController.php to $this->_redirectReferer();
and update the form phtml to include the error/success message by editing app/design/frontend/base/default/template/contacts/form.phtml and adding the line <?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?> in messages_product_view
Best to copy the files to 'local'

Resources