Forums

Page title as subject

orsat 30 Nov, 2007
First of all, great component, donation on its way🙂

Is it possible to have the page title from which the form was sent as the e-mail subject?

Thank you in advance
GreyHead 30 Nov, 2007
Hi orsat,

You can get the page title from the Joomla $mainframe object. To use it put this code in the 'Onsubmit - before email field
<?php
global $mainframe;
$rows[0]->emailsubject = $mainframe->getPageTitle();
?>
and make sure that the other Subject fields are clear.

Bob
orsat 30 Nov, 2007
Thank you for the quick reply, I did what you suggested but I am getting this message:

If you choosed to email results than you must ad: Email Address, Email subject, From Name and From Email

In Form Html I have a very basic form:
Name: <br>
  <input name="name"><br>
Email:<br>
  <input name="Email"><br>
Comment:<br>
  <textarea cols="40" rows="10" name="comment"></textarea><br>
  <button name="submit">Submit</button><br>
In On Submit code - before sending email: I have what you suggested:
<?php
global $mainframe;
$rows[0]->emailsubject = $mainframe->getPageTitle();
?>
Any idea what I am doing wrong?

Again, thank you for the great support !
GreyHead 30 Nov, 2007
Hi orsat,

Assuming that the other three fields are completed, please just put something - 'XXX' will do - in the Subject field on the General tab. The other code snippet will (I hope) overwrite this before the email is sent.

Bob
orsat 30 Nov, 2007
OK, the page title is being send as the email subject, however the email subject displays the global site title, not the article title.

The reason I need this is that I have a site with many excursions, tours and accommodation offers. Ideally what I would like to do is to get the article title as the e-mail subject (that way the mail administrator knowns what department to forward the email to) and also display the article title at the beginning of the form when a visitor clicks on the link for booking the tour.

Example:

Requested tour: Article title

Name...
E-mail...
Comments..

By the way, I installed the plugin and tried to call it within a excursion offer page, but I still only get the global site title as the email subject.

Could you please provide more assistance how to achieve this.

Thanks in advance...

P.S I might have some custom work for you guys, a client needs a special component dealing with XML files, what is the best way to contact you on that matter?
Max_admin 30 Nov, 2007
Hi Orsat,

you can use this query to get you the current content item title :
<?php
$database->setQuery( "
  SELECT title 
    FROM #__content 
    WHERE id='".$_GET['id']."'" );
$title = $database->loadResult();
?>
put this code at the top of the HTML box and later you can use Bob's hack and just replace the $mainframe->getPageTitle() with $title and thats will do it!

If you ever got some contract work then you can post details at the "paid services forum" here, if you dont like to post the details then post a request and somebody will give a reply about the best method of contact🙂

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
orsat 30 Nov, 2007
Great support, please bear with me for the last time on this matter🙂

At the moment I have:
<?php
$database->setQuery( "
  SELECT title 
    FROM #__content 
    WHERE id='".$_GET['id']."'" );
$title = $database->loadResult();

//put the article title in the email subject
$rows[0]->emailsubject = $title;

//display the article title on the page with the form
echo $title;
?>
The article title displays nicely on the page with the form, however the article title is still not send as email subject. Do I have to place the second part of the code in the "On Submit code - before sending email" field?

Thanks...<br><br>Post edited by: admin, at: 2007/12/01 10:00
Max_admin 01 Dec, 2007
Hi Orsat,

Actually you should put this in the "onsubmit before email" :

<?php
$database->setQuery( "SELECT title FROM #__content WHERE id='".$_GET['id']."'" );
$title = $database->loadResult();

//put the article title in the email subject
$rows[0]->emailsubject = $title;

?>
Cheers

Max<br><br>Post edited by: GreyHead, at: 2007/12/01 13:30Hi Orsat,

Actually you should put this in the "onsubmit before email" :
<?php
$database->setQuery( "SELECT title FROM #__content WHERE id='".$_GET['id']."'" );
$title = $database->loadResult();

//put the article title in the email subject
$rows[0]->emailsubject = $title;

?>
Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
minimalniemand 06 Dec, 2007
Hi,

just found this thread and its exactly what I need. I just cant get it to work.
The Subject line is empty.
I think I made everything like described here. As orsat, I also managed to get the site title sent, but not the article title

I copied the code directly to my onSubmit - before sending mail - field:
<?php
$database->setQuery( "SELECT title FROM #__content WHERE id='".$_GET['id']."'" );
$title = $database->loadResult();

//put the article title in the email subject
$rows[0]->emailsubject = $title;

?>
I dont have a subject field on my form. The "subject" on the general tab (chrono config) contains 'XXX'

pls tell me if I can provide you with further information
GreyHead 06 Dec, 2007
Hi minimalniemand,

Please try adding these diagnostics:
<?php
$database->setQuery( "SELECT title FROM #__content WHERE id='".$_GET['id']."'" );
$title = $database->loadResult();

//put the article title in the email subject
$rows[0]->emailsubject = $title;
if ( $debug ) {
  $rows[0]->redirecturl = "";
  echo "_GET: ";print_r($_GET['id']);echo "<br />";
  echo "_GET: ";print_r($title]);echo "<br />";
  echo "_GET: ";print_r($rows[0]->emailsubject);echo "<br />";
}
?>
Now please turn on debug in the General tab, submit the form and see what shows up.

Thanks

Bob
orsat 14 Dec, 2007
Thank you for all the help. I will try your last suggestion and post the diagnostics as soon as I get the time. In the meantime I did get the form to send the article title (I am not a coder so the code can for sure be improved🙂

Here is what works for me. I wanted to both display the article title in the form (since it is a tour booking form I wanted the customer to see the name of the tour he is booking), and send it as the E-mail subject:

Form HTML:
<input name="subject" type="text" size="40" value="<?php
$database->setQuery( "SELECT title FROM #__content WHERE id='".$_GET['id']."'" );
        $title = $database->loadResult(); 
echo $title;
?>">

Name: <br>
  <input name="name"><br>
Email:<br>
  <input name="Email"><br>
Comment:<br>
  <textarea cols="40" rows="10" name="comment"></textarea><br>
  <button name="submit">Submit</button>
On Submit code - before sending email:
<?php
global $mainframe;
$rows[0]->emailsubject = $title;
?>
On Submit code - after sending email:
<?php
echo "Thank you for contacting ... !";
?>


I also would love to see a calendar implementation for date selection.
GreyHead 14 Dec, 2007
Hi orsat,

That looks good to me, I'd just clean the first piece of php in the html code a little:
<?php
$sql = 
    SELECT title 
        FROM #__content 
        WHERE id='".$_GET['id']."'";
$database->setQuery( $sql );
$title = $database->loadResult(); 
?>
<input name="subject" type="text" size="40" value="<?php echo $title; ?>" />
. . .
I prefer to separate finding the variable values and displaying them as much as I can, but it is a question of taste.

Bob
orsat 26 Dec, 2007
Just purchased 2 licenses, I just need one so consider the second license to be the donation I promised🙂

The code for displaying and sending the article title works just fine when the form is published within the article (via the plugin).

Now to the new challenge🙂)

What I really need is to have only a link somewhere within the article pointing to the reservation form, the form should open in a new window and the article title should be displayed as the first line in the form and, when submitted, the article title should be the e-mail title.

The code above doesn´t work if I call the form from a link.

Any help is GREATLY appreciated.
GreyHead 27 Dec, 2007
Hi orsat,

On Max's behalf - thanks for buying the licenses.

Should be straightforward to set up the links you want. You could do it with just a text link using the $_GET array to pass the variables from a link like <!-- w --><a class="postlink" href="http://www.mysite.com?link_from=article_title">www.mysite.com?link_from=article_title</a><!-- w --> but I think you'd get more functionality from using a full form. So . . .

Set up a ChronoForms form with a hidden field called link_from with the value set to the article title and a submit button that you customise to suit your article. (You can have this saved to the database if you want to be able to track click-throughs in which case you'd probably want to add a hidden id field.) Build a little custom redirect code for the OnSubmit code box to call the second form and pass the key data over.

Embed this into your article page.

Now create your full form including the code in the form html to pull up the article title. I'd probably save the data into the database and just pass the id to allow it to be read into the second form.

Is this sketch enough or does the form code need to be spelt out in more detail?

Bob
orsat 27 Dec, 2007

Is this sketch enough or does the form code need to be spelt out in more detail?



The more detail, the better🙂 my coding skills are really bad


This is what I had in mind (did this on old joomla and worked like a charm):

I customized the part of code that displayed the PDF icon replacing it with the "reservation" link. Now I could just enable or disable the PDF icon for any page and the "reservation" link would show where needed.

I will give it a try at what you suggested, in the meantime, if you find the time I would really appreciate if you could give me some coding example that I can build on...


Thanks a lot
Max_admin 28 Dec, 2007
Hi Orsat,

Thank you very much, so at the last code posted by Bob, we will edit it so its only one line for our case here :

<input name="subject" type="text" size="40" 
  value="<?php echo $_GET['subject']; ?>" />
and assuming that the link to the form has contained a variable at the end called : subject=this_is_the_subject

please try it and let me know! :-)

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
minimalniemand 10 Jan, 2008
Hello people,

this project I worked on, was degraded to 'not so important', so I could not test this until now.
What should I say? It works! Thx for the support, will buy (respectively the company I work for) a license the next days ...
GreyHead 11 Jan, 2008
Hi minimalniemand,

Thanks and good luck.

Bob
colinan 29 Apr, 2010
Hi Bob
I've read through this thread and it seems to address my needs exactly - get the title of the page an email form is embedded (with Chronocontact plugin) in and give that title as the subject of the email.
Problem is I am a complete code noob - haven't written code since 1985 and my understanding of serious html etc coding is rudimentary at best. I tried using Orsat's code and got an error when I loaded the article. I put the form one just above the tags for the captcha I'm using.
Can you give me code snippets and very clear instructions on where to put them to accomplish the objective?
While I'm here... how can I edit the form - to add a comments field? I have only visitors name and email now?
Thanks
GreyHead 08 May, 2010
Hi Colinan,

Do you still need this?

You can edit the Form HTML from the Form Editor | Form Code tab.

Bob
Jeff Gietz 20 Aug, 2010
It's been a while since any previous post but I thought I would put up my solution as I couldn't get any other one to work.
I used orsat's way of getting the title

Form HTML:

<input name="subject" type="text" size="40" value="<?php
$database->setQuery( "SELECT title FROM #__content WHERE id='".$_GET['id']."'" );
        $title = $database->loadResult(); 
echo $title;
?>">


and then used a hidden field (as the user wouldn't need to see what page they were on for my example)
<input name="page" type="hidden" value="<?php
$database->setQuery( "SELECT title FROM #__content WHERE id='".$_GET['id']."'" );
        $title = $database->loadResult();
echo $title;
?>">

Then in the "Setup email" portion of form management I added a dynamic subject and put page into it.
orsat 09 Dec, 2011
Hi all,

Well, the solution described in this thread is working very well in Joomla 1.5. Now I am on the quest to make this work with Joomla 1.7 as well, will start testing today but would appreciate any feedback as to the possible code changes needed. I know that the "Get age title" in Joomla 1.7 is different.


Since it appears that there are several people who need this I thought that we could discuss it here🙂

The idea is simple (I use this to offer tours and other services booking for a travel agency), use the pdf, e-mail or print buttons in Joomla articles to display the link to the form (that way you can turn them on and off easily through article administration), upon clicking the link to the form the form is displayed with the page title inserted into the first inputbox automaticaly. Also the page title should automaticaly also be send as the e-mail subject.

Note: I plan to do this for regular articles, as well as for K2 articles.

Form is pretty basic

1. Selected tour (page title automatically inserted here)
2. Name and Surname
3. Customer info
4. Date picker (arrival)
5. Date picker (departure)



Anyway, all input and ideas are appreciated..

Lets see some code... 🙂
orsat 09 Dec, 2011
OK, to start:

In Joomla 1.5 to get the article title we had
<?php 
global $mainframe;
$database =& JFactory::getDBO();
$query = "SELECT title FROM #__content WHERE id='".$_GET['articleid']."'";
$database->setQuery( $query );
$title = $database->loadResult();
//echo "Title: " . $title;
?>



For Joomla 1.7 could we use this?
<?php
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
    $ids = explode(':',JRequest::getString('id'));
    $article_id = $ids[0];
    $article =& JTable::getInstance("content");
    $article->load($article_id);
    echo $article->get("title");
}
?>
GreyHead 17 Dec, 2011
Hi Orsat,

Have you got this working now?

Bob
orsat 23 Dec, 2011
Hi GreyHead,

Did not have the time to test as having 2 kids and preparing for Christmas does not leave much space for work🙂

I am planing to dive into this as soon as possible, if you have any suggestions would be great, as I sad, for people who need a simple booking/inquiry solution this is perfect because if you can live without having a "create PDF" icon within the joomla article you can easily have a link pointing to the booking form and the page title tells you what service the customer is interested in.


Anyway, will post of progress as soon as I have tested this...


Regards,

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