Thejas
Thejas

Reputation: 353

using window.location in joomla 3

I am working on a project that someone already done in joomla. I have to fix some issues in there.

They have a place order component in joomla 3.0. There are two options in main page. One is placing a regular order and other is special order. They are given as radio buttons. On each button there is onclick function written as follows

onclick='window.location.href=("<?php echo JRoute::_('index.php?option=com_order'); ?>")'

onclick='window.location.href=("<?php echo JRoute::_('index.php?option=com_order&ordertype=2'); ?>")'

The first button will form url as follows.

index.php?option=com_order&view=form&layout=edit&Itemid=516&lang=en

but for second one the url is not correct and it gives some error.

index.php?ordertype=2&option=com_order&Itemid=516&lang=en

Note that second url is missing parameters view=form&layout=edit. How can I fix this? Should I add a new menu item. If yes what type? Or just hard code the url in window.location.href directly?

Upvotes: 0

Views: 602

Answers (3)

Thejas
Thejas

Reputation: 353

Thank you all for the answers. I have used just another way to fix this issue.

<?php $u = JURI::getInstance();
$u->setVar( 'ordertype', '2' );?>
onclick='window.location.href=("<?php echo JRoute::_($u->toString()); ?>")'

Upvotes: 1

jonasfh
jonasfh

Reputation: 4579

My first suggestion would be to just move the &ordertype=2- part out of the JRoute::_() - call, as this seems to confuse JRoute.

So try to use:

onclick='window.location.href=("<?php 
  echo JRoute::_('index.php?option=com_order') . '&ordertype=2'; 
?>")'

(It's a little ugly, and bquarta might be right, though :)

Upvotes: 1

bquarta
bquarta

Reputation: 569

This is just a random shot, but if you have a look at the JRoute-Definition here it says there are three options: _($url, $xhtml=true, $ssl=null)

The second one sounds interesting to me:

$xhtml Replace & by & for xml compilance

Maybe set this option to false, to see what happens with your link?

The part in the code that is triggered by that looks like this:

if($xhtml) {
    $url = str_replace( '&', '&amp;', $url );
}

So setting this to false would at least not str_replace the & (which is the only crucial difference i can see between both cases)... I know there is a reason for replacing this, but... well... if you're using utf8, it shouldn't be a problem i guess...

I mean... another thing, that is definitely strange is that JRoute seems to flip the option and the ordertype-parameter... for whatever reason.

Hope i could at least give some input in this :D

regards

Upvotes: 1

Related Questions