This Question has been asked earlier also.
*Best Answer was*
In order to use joomla default recaptcha plugin follow these steps-
1)Get recaptcha keys from http://www.google.com/recaptcha
2)Set these keys to recaptcha plugin and activate it if it's not.
3)Put below code where you want to show recaptcha
//php code
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onInit','dynamic_recaptcha_1');
//html code inside form tag
<div id="dynamic_recaptcha_1"></div>
4)Put this code where you validating/processing the form:
$post = JRequest::get('post');
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$res = $dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);
if(!$res[0]){
die('Invalid Captcha');
}
//For Joomla 3.x
$post = JFactory::getApplication->input->post;
$dispatcher = JEventDispatcher::getInstance();
But as i'm new to joomla where do i write these codes?
3) This has to be in the view where you display the form, mostly in the file com_example/views/form/tmpl/edit.php.
4) This has to be in the controllers save action, mostly in the file com_example/controllers/item.php. Item.php is the file of your object, for example on com_content this file has the name article.php.
Related
I am using CodeIgniter for PayPal Standard payments. Everything works fine, but I want PayPal to display a shopping cart icon with the amount and currency on its pages. Here is my code; how can I accomplish adding that?
function buy($id){
// Set variables for paypal form
$returnURL = base_url() . 'paypal/success';
$cancelURL = base_url() . 'paypal/cancel';
$notifyURL = base_url() . 'paypal/ipn';
// Get product data from the database
$product = $this->product->getRows($id);
// Get current user ID from the session
// $userID = $_SESSION['userID'];
// Add fields to paypal form
$this->paypal_lib->add_field('return', $returnURL);
$this->paypal_lib->add_field('cancel_return', $cancelURL);
$this->paypal_lib->add_field('notify_url', $notifyURL);
$this->paypal_lib->add_field('item_name', $product['name']);
// $this->paypal_lib->add_field('custom', $userID);
$this->paypal_lib->add_field('custom', 1);
$this->paypal_lib->add_field('item_number', $product['id']);
$this->paypal_lib->add_field('amount', $product['price']);
// Render paypal form
$this->paypal_lib->paypal_auto_form();
}
The sample you provided is considered an old/legacy solution by PayPal and is not recommended. So rather than tell you how to fiddle with something so old, I instead recommend you ditch the above function and use something nicer. Here is a demo that can act as a base for your front-end:
https://developer.paypal.com/demo/checkout/#/pattern/client
It's all just HTML/JavaScript, so get it working on its own (in a .html file) first and then once it is working, save a backup copy, and then have your PHP application just output it when appropriate.
If you want individual item data to show, you will need to extend the "purchase_units" array. Otherwise it will just be the amount and currency. You can find a sample purchase_units array here: https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/ See the v2/orders API spec for the full documentation.
I found this page on how to implement custom field in article:
http://docs.joomla.org/Adding_custom_fields_to_the_article_component
and it works well, but only in article view.
What should I do else, to make it show that custom field in each article, when
in category blog view?
I tried adding :
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('content', 'plg_content_rating');
$results = $dispatcher->trigger('onContentPrepare',
array('com_content.category', & $this->item, & $this->item->params, 0));
to my category blog override file, but that didn't work.
Also in components/com_content/views/category/view.html.php file,
there is a line like this:
$results = $dispatcher->trigger('onContentPrepare',
array ('com_content.category', &$item, &$this->params, 0));
Shouldn't that already trigger all registered content plugins?
The similar line in article's view.html.php file, works well for that
purpose.
I'm going through the Joomla 2.5 tutorial to build a custom component. Now I'm facing an issue on the redirection after using JToolbar::save() or JToolBarHelper::cancel for that matter. By default Joomla wants to redirect to the default layout (from the edit layout). However I don't want it to do that. I want it to redirect back to another view. In Joomla 1.5 I would have done this through adding the function into the controller - something like
function cancel()
{
//redirects user back to blog homepage with Cancellation Message
$msg = JText::_( 'COM_BLOG_POST_CANCELLED' );
$this->setRedirect( 'index.php?option=com_jjblog&view=jjblog', $msg );
}
Now that works beautifully for the cancel function, however for save this is a much more complex thing. If I want to overwrite the url do I have to redirect the controller to the model and then write in all the code for the model interaction? Because that seems slightly excessive just for a url redirection like you would in Joomla 1.5?
Hope you have added the save toolbar code with the proper controller name like this
JToolBarHelper::save('controllerName.save');
Create a save function in appropriate controller.
Add the task in the form
Finnally make sure you have added form action withthe corresponding component name.
You can try this-
In the controller firstly you call the parent save function than redirect to url.
function save(){
parent::save();
$this->setredirect('index.php?option=com_mycomponent');
}
OK it didn't need to $this->setRedirect at all. Just needed me to change the value to
protected $view_list = 'jjBlog';
which then sets the redirects of everything back to that list view.
Source link for this is here.
Thanks for all the responses though!!
view.html.php
protected function addToolbar ()
{
JRequest::setVar ('hidemainmenu', false);
JToolBarHelper::title (JText::_ ('Configuration'), 'configuration.gif');
JToolBarHelper::save($task = 'save', $alt = 'JTOOLBAR_SAVE');
}
controller.php
public function save()
{
$mainframe = JFactory::getApplication();
$mainframe->enqueueMessage (JText::_ ('COM_SOCIALLOGIN_SETTING_SAVED'));
$this->setRedirect (JRoute::_ ('index.php', false));
}
I think you can use
global $mainframe;
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
If you are overriding joomla's default save function in your custom component like
function save( $task = 'CustomSave', $alt = 'Save' ) // or even same name Save
Inside your controller you can use the CustomSave as the task and use $mainframe for redirect.
or
$mainframe = &JFactory::getApplication();
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
Hope this may help you..
I am currently displaying a list of products on pyrocms page. Using plugin i get the products from db tables and display them as a list i want to use pagination but have no idea how to use it and where to start from. Does any one know any tutorial or have some suggstion?
You won't need to load pagination library or initialize it. It is a little different from you do in regular codeigniter, also you can surely use the way you do it in codeigniter pagination class
I usually do this for pagination.
in your controller use this
....
// Create pagination links
$total_rows = $this->products_m->count_all_products();
$pagination = create_pagination('products/list', $total_rows);
//notice that product/list is your controller/method you want to see pagination there
// Using this data, get the relevant results
$params = array(
'limit' => $pagination['limit']
);
$this_page_products = $this->product_m->get_all_products($params);
....
//you got to pass $pagination to the view
$this->template
->set('pagination', $pagination)
->set('products', $this_page_products)
->build('products/view');
obviously, you will have a model named products_m
At your model this would be your get_all_products function, I am sure you can build the count_all_products() function too
private function get_all_products($params){
//your query to get products here
// use $this->db->limit();
// Limit the results based on 1 number or 2 (2nd is offset)
if (isset($params['limit']) && is_array($params['limit']))
$this->db->limit($params['limit'][0], $params['limit'][1]);
elseif (isset($params['limit']))
$this->db->limit($params['limit']);
//rest of your query and return
}
Now at your view you have to foreach in your passed $products variable and to show pagination links use this line in your view
<?php echo $pagination['links'];?>
I use this in my works, hope it help.
Pyrocms used codeigniter framework this code works perfectly in case of module but i have never tried this on a plugin but still you can try this.
Load pagination library in Controller
$this->load->library('pagination');
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20;
$this->pagination->initialize($config);
Use this code in view to genrate the links
echo $this->pagination->create_links();
Can anyone please help me with the process flow through which the Joomla Itemid parameter ends up being the highlighted menu item?
I have embedded a 3rd party application in Joomla and by temporarily changing the php environment within the application.
I am able to get joomla html and insert the 3rd party html by replacing a token.
Simplified Code:
if ($_SERVER['REQUEST_METHOD'] == 'GET' ) {
$_SERVER['REQUEST_METHOD'] = '';
}
$_SERVER['REQUEST_URI'] = '/joomla/index.php?view=mycom&option=com_mycom&Itemid=103';
$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = '/joomla/index.php';
$_SERVER['QUERY_STRING'] = 'view=mycom&option=com_mycom&Itemid=103';
ob_start();
require_once '/joomla/index.php';
$joomlaHTML = ob_get_clean();
echo str_replace($replacementToken, $thirdPartyHTML, $joomlaHTML);
In v1.5.x, the menu item with ID 103 is properly highlighted but in v2.5.6, it isn't and the Home item is always highlighted. I think it used to be highlighted correctly in v1.6.x and earlier versions of 2.5.x as well but not sure.
I wanted to find how the process flows (where this is set) so I can see what tweaks I need to make.
DELETED WRONG INFO
Thanks Dayo! you saved my day with this:
// force highlight the external url menu item
$Itemid = JRequest::getVar('Itemid');
$menu = JSite::getMenu();
$menu->setActive($Itemid);
I don't fully understand the breadcrumb part, but I managed to get it working by editing my component's controller.php to read:
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// force highlight the external url menu item
$Itemid = JRequest::getVar('Itemid');
$menu = JSite::getMenu();
$menu->setActive($Itemid);
// force fix the breadcrumb
$app = JFactory::getApplication('site');
$pathway =& $app->getPathway();
$bcrumbs = &JPathway::getInstance('site');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* MyCom Component Controller
*/
class MyComController extends JController
{
}
Look in the following File
Check the
/modules/mod_menu/mod_menu.php
File and you will see two functions has been called "getActive" and "getDefault"
Which can be find in following file
/libraries/joomla/application/menu.php
I think it can be customized easily now