Add article title to form

Add an article title to a ChronoForms form for email subjects.

Overview

The issue occurs because the standard method to get the page title retrieves the browser or menu title, not the specific article title.
Use a custom element with pure code to fetch the article ID from the URL and load the correct title from the Joomla content table.

Answered
iW iWim 23 Feb, 2014
Hello,

I'm a first time poster, long time user of Chronoforms.
And I have a question I can't seem to find the answer to.

I have set up a website with Joomla 3.2.2 and Chronoforms 4.0.4 and the plugin (4.0.3) to add forms to articles.
And I'd like to be able to add the article title to the mail subject.

While searching I found two topics. One with a dead link and another using a custom element with the following code:
<?php $doc =& JFactory::getDocument(); ?>
<input type='hidden' name='page_title' id='page_title' value='<?php echo $doc->getTitle(); ?>' />

However this does not get the article title in the form.
This gives me the browser title of the menu item that is linked to the category of the article.

Strangely when I echo $doc->getTitle(); directly into the index.php file of my template it does display the article title on the page.
More strangely when I use this code in the template AND in the form, it displays the article title on the page and the browser title of the menu item in the form!

Has this code stopped working? Or did I miss something?

Thank you.
Wim
Gr GreyHead 23 Feb, 2014
Hi Wim,

That code is from this FAQ and should give you the current page title (which may not be the same as the article title).

To be sure of getting the Article title you my need to get the article ID from the URL and look up the title. I'm no expert in the ways that Joomla! handles titles though :-(

Bob
iW iWim 24 Feb, 2014
Answer
Ok, another day, another search...
I found it. Maybe it is also interesting for other CF users.

I got the code from http://blog.calebnance.com/joomla-2.5/how-to-get-a-joomla-2.5-article-title-in-template.html

I added a custom element to the form.
Selected 'Pure code'

In the code area I put:
<?php  $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; ?>' />
This topic is locked and no more replies can be posted.