Forums

Data from page title

dkulot 10 Jun, 2011
Hi!

I have a form with standard fields (name, phone...) and that form shows in several articles, components... I would like to get web page Title in e-mail, when user submit the mail.

Is it possible? Thanks!
GreyHead 10 Jun, 2011
Hi dkulot ,

I think you can get the page title (not necessarily the article title) from:
<?php
$doc =& JFactory::getDocument();
?>
<input type='hidden' name='title' id='title' value='<?php echo $doc->getTitle(); ?>' />


Bob
sradug 03 Aug, 2011
Hello
i think that one of the upgrades for the chronoform will be to get the email subject from the article title-or to have the option in the form to select the subject-from page title/article title/user defined title, etc
what do you think?
as of rigt now i am using a form in 7 pages/articles and i would love to get as subject the article/page title

i know you put the code above. do you think you can point me in the right direction where to paste it?
shall i put it in the form code?
there's only divs there
thank you again for everything
Radu
http://weddingphotographerinchicago.com
GreyHead 03 Aug, 2011
Hi Radu,

Which version of ChronoForms are you using? You can find the version from Site Admin | Extensions | Install/Uninstall | Components in Joomla! 1.5 or Site Admin | Extensions | Extension Manager | Manage in Joomla! 1.6.

Bob
sradug 04 Aug, 2011
4.0 RC1.8 17 Apr 2011 Chronoman
thank you-version
GreyHead 04 Aug, 2011
Hi Radu,

In CFv4 drag a Custom Element into the Preview box and add the code there.

Bob

PS I suggest you update to RC1.9 as there are some bug-fixes included.
sradug 04 Aug, 2011
Parse error: syntax error, unexpected '<' in /administrator/components/com_chronoforms/form_actions/show_html/cfaction_show_html.php(99) : eval()'d code on line 10


Here's what ive done
1.in preview mode i drag custom element
2.paste this code
<?php
$doc =& JFactory::getDocument();
<input type='hidden' name='title' id='title' value='<?php echo $doc->getTitle(); ?>' />
?>
3.tried both options for output code..... in custom element setting
4 save form
5 checked on website

Thank you in advance for this
PS do you think the SEO settings have something to do with the code
Q: in order to do the update i have to save-forms then restore them or will update w chronoforms new version?
Thank you
GreyHead 05 Aug, 2011
Hi sradug,

Apologies, there was an error in my post (now fixed). Please try
<?php
$doc =& JFactory::getDocument();
?>
<input type='hidden' name='title' id='title' value='<?php echo $doc->getTitle(); ?>' />

Bob
sradug 06 Aug, 2011
Bob , thank you again for the code
i've loaded the form with it in a custom element
i also disable and enable the corecaptcha
my form works like before
but does not collect the page title name

maybe in a future release will get the script automatically included.
i did not give up yet.
i am thinking that might have to do with seo enabled.
you can take a look here
http://bestchicagolimousine.com/luxury-sedan.html
i have the form in any fleet page
i think you got the point
thank you again
Radu http://weddingphotographerinchicago.com/
GreyHead 06 Aug, 2011
Hi Radu,

It's working OK.

Bob
sradug 06 Aug, 2011
I see that
i think you have to baby sit me one more time on this because my email does not collect that value
i've added to the template
<p>Limo Type = {input_custom_10}</p>
but for some reason does not collect the hiden field
do you think i have to add the field in the form in the attachments area?
like field 10?
Than you again Bob

here;s what i collect on the email


Limo = {input_custom_10}
Name = Me
Phone = 1234567890
Email = [email]me@email.com[/email]
Message = blablabla

Submitted by 123.567.890.
GreyHead 06 Aug, 2011
Hi Radu,

The name of the hidden input is 'title' so you need {title} in the Email template.

Bob
sradug 06 Aug, 2011
thank you it works!
LuckyLuke 11 Feb, 2012
Hi everyone,

The code mentioned in this thread sends an article title with form.
That's great!
But,

Is there a code that sends an article CONTENT with form?

One type of form would be on several pages, often with similar titles.
I want to be sure from what page the user sent me the form.

regards,
Luke
GreyHead 13 Feb, 2012
Hi Luke,

Better to get the article ID which will uniquely identify the article. If you have that (or the title) you can look up the record in the #__content table and get any or all of the contents. NB This won't work reliably on title if there are duplicated titles.

Bob
Marcel_501 19 May, 2012
Hi all,

Just read this post and got everything working. However, as Greyhead already mentioned, this catches the page title. In the last post I read that it would be better to catch the article ID. My question obviously: how to do this?
GreyHead 19 May, 2012
Hi Marcel_501,

Please try this
<?php
$input = new JInput();
$view = $input->get('view');
$id = $input->get('id');
if ( $view != 'article' ) {
  $id = false;
}
$form->data['article_id'] = $id; 
?>


Bob
Marcel_501 19 May, 2012
Hi GreyHead and thanks for the quick reply. Where exactly do I have to put the code. The code with which it worked was put into a hidden field. I've put the code you mentioned in this field as well but apparently nothing happens.

<?php
$input = new JInput();
$view = $input->get('view');
$id = $input->get('id');
if ( $view != 'article' ) {
  $id = false;
}
$form->data['article_id'] = $id; 
?>
<?php
$doc =& JFactory::getDocument();
?>
<input type='hidden' name='title' id='title' value='<?php echo $doc->getTitle(); ?>' />


This is how the code looks now...

BTW: is it only possible to mention the article ID in the message, or is the complete title text an option as well?
GreyHead 20 May, 2012
Hi Marcel,

Err, I think that needs to be
<?php
$input = new JInput();
$view = $input->get('view');
$id = $input->get('id');
if ( $view != 'article' ) {
  $id = false;
}
$form->data['article_id'] = $id;
?>

<input type='hidden' name='title' id='title' value='<?php echo $form->data['article_id']; ?>' />

You could add the title as well but if you have the ID it's easy to look up the title - or anything else - when you need it.

Bob
Marcel_501 20 May, 2012
Thanks GreyHead, code seems to be working fine. Sorry to keep you bothering but how can I now translate the ID to the actual title being mentioned in the email. My client only needs to see from what product page the email was send so he can contact the person who send it right away, knowing in which product he is interested in.
cjmicro 24 May, 2012
This worked for me too, thanks! But I also would like to have the title, not the article ID show up. If anyone can help that would be so great!
cjmicro 24 May, 2012
Actually this code shows the page title or something... not the article title or ID. (the menu title?)

I would like it to show the actual article title. I have the form displayed in the article via CF plugin and need the title of that article to show up. Thanks
GreyHead 25 May, 2012
Hi Cheryl,

Which code are you using? There is code in this thread to show the page title and code to show the article id.

If you check the recent post for the article ID then I think that replacing
$id = $input->get('id');
with
$id = $input->get('title');
will get you the article title

Bob
Marcel_501 03 Jun, 2012
Hi Greyhead,

Tried what you suggested but instead of getting the title, ,nothing is displayed in the email I receive.

Any idea?
cjmicro 03 Jun, 2012
I couldn't get it either but ended up downloading ($10) Bob's free dynamic action and that worked and was really easy!

http://greyhead.net/

Thanks Bob!
GreyHead 04 Jun, 2012
Hi marcel_501,

You're right, you have to look it up if you use this code:
<?php
$input = new JInput();
$view = $input->get('view');
$id = $input->get('id');
$form->data['article_id'] = '';
$form->data['article_title'] = '';
if ( $view == 'article' ) {
  $form->data['article_id'] = $id;
  $db =& JFactory::getDBO();
  $query = "
    SELECT `title`
        FROM `#__content`
        WHERE `id` = '{$id}' ;
  ";
  $db->setQuery($query);
  $title = $db->loadResult();
  $form->data['article_title'] = $title;
}
?>
<input type='hidden' name='title' id='title' value='<?php echo $form->data['article_title']; ?>' />

Bob
Marcel_501 10 Jun, 2012
Thanks Greyhead, that worked. For those who are using this code I think the exact code should be this:

<?php
$input = new JInput();
$view = $input->get('view');
$id = $input->get('id');
$form->data['article_id'] = '';
$form->data['article_title'] = '';
if ( $view == 'article' ) {
  $form->data['article_id'] = $id;
  $db =& JFactory::getDBO();
  $query = "
    SELECT `title`
        FROM `#__content`
        WHERE `id` = '{$id}' ;
  ";
  $db->setQuery($query);
  $title = $db->loadResult();
  $form->data['article_title'] = $title;}
?>
<input type='hidden' name='title' id='title' value='<?php echo $form->data['article_title']; ?>' />
Sjorzzzie 26 Jul, 2012
Nice code! Works also with Joomla 2.5.6 and Chronoforms 4.0

Is it also posible to extract the creation date of the article?
GreyHead 27 Jul, 2012
Hi Sjorzzie,

I think so, please try this:
<?php
$input = new JInput();
$view = $input->get('view');
$id = $input->get('id');
$form->data['article_id'] = '';
$form->data['article_title'] = '';
if ( $view == 'article' ) {
  $form->data['article_id'] = $id;
  $db =& JFactory::getDBO();
  $query = "
    SELECT `title`, `created`
        FROM `#__content`
        WHERE `id` = '{$id}' ;
  ";
  $db->setQuery($query);
  $article = $db->loadObject();
  $form->data['article_title'] = $article->title;
  // add code to re-format the date if needed 
  $form->data['article_created'] = $article->created;
}
?>
<input type='hidden' name='title' id='title' value='<?php echo $form->data['article_title']; ?>' />
<input type='hidden' name='created' id='created' value='<?php echo $form->data['article_created']; ?>' />

Bob
Sjorzzzie 27 Jul, 2012
Hi bob,

Thanks for the quick reply!
Your code works. Only strange thing is that the creation date of the article is: 2012-09-03 18:00:00
And in the form it says: 2012-09-03 16:00:00

That is 2 hours off? My time zone is Amsterdam...
GreyHead 27 Jul, 2012
Hi Sjorzzzie,

The code I wrote will give you the time recorded in the database. It looks as though that is UTC which is two hours off CET. Try changing the SELECT line to
SELECT `title`, DATE_ADD(`created`, INTERVAL 2 HOUR) AS `created`


Bob
Sjorzzzie 27 Jul, 2012
Thanks bob! Works perfect!
GreyHead 27 Jul, 2012
Hi Sjorzzzie,

Great. You should make a note to check when Daylight Saving Time ends in December. It may need to be changed - I don't know how that works.

Bob
This topic is locked and no more replies can be posted.