Buy Now
Sign in

FAQ search

How can I get information about the current page?

Details
Published: Monday, 24 February 2014 14:27

If you are using your ChronoForm in a plug-in or module it can be useful to add information about the current page to the form results. Here are ways to add the page URL or title.

For the URL add a Custom Element from the Advanced Elements Group to the Preview box, check the Pure Code box and put this into the Code box:

<input type='hidden' name='page_url' id='page_url' value='<?php echo \JURI::getInstance()->toString(); ?>' />

For the page title use this code:

<?php
$jdoc = \JFactory::getDocument();
?>
<input type='hidden' name='page_title' id='page_title' value='<?php echo $jdoc->getTitle(); ?>' />
You can also get the page URL from $jdoc like this:
<?php
$jdoc = \JFactory::getDocument();
?>
<input type='hidden' name='page_url' id='page_url' value='<?php echo $jdoc->getBase(); ?>' />

The Article title

The page title is not always the same as the article title. If the Article ID is available from the page URL you can get the title like this:
<?php
$article_title = '';
$id = \JRequest::getInt('id', '');
$article = \JTable::getInstance('content');
$article->load($id);
$article_title = $article->get('title');
?>
<input type='hidden' name='page_title' id='page_title' value='<?php echo $article_title; ?>' />

Thanks to user iWim for this code.