Automatic input of document page title into form

arvendal 17 Jul, 2008
Hi,

I need to know how I in a simple way can get an automatic input of the document title into a Chronoform. Let's say this is the case:
[list=1]
  • A form called "More info" is created in Chronoform.

  • The form is added via plugin to let's say 5 different articles

  • Each article has a specific page title <title>

  • The page title is automatically added to the form and sent to the recipient, thus showing on which matter more information is requested
  • [/list:o]
    Hope you get my point. The aim is to bring down the number of forms to maintain. It would be great to have just one form for several topics/articles.

    Thanks
    --Arvendal
    GreyHead 18 Jul, 2008
    Hi Arvendal,

    You can possibly get some page info from the $mainframe object - see this post for a starter - though this didn't seem to give the page title.

    Bob
    arvendal 19 Jul, 2008
    Hi,

    I like your fast replies!

    Unfortunately my knowledge in PHP scripting is poor and therefor I can't see what to do with your advice.

    But I found another Q&A at your forum that seems to address my problem, or at least provide the same result I am looking for. Since sendmail doesn't work on my local wampserver, I need to test this on a real web server. I will do that and get back to you with the result.

    Any more advice you have is always welcome!

    Yours
    --Mats Arvendal
    GreyHead 19 Jul, 2008
    Hi Mats,

    Yes, that other thread looks good (I've cleaned up all the code that was messed up by the forum change I hope).

    If you have a gmail or hotmail account you may find that you can use their mail servers with a wamp server.

    Bob
    arvendal 19 Jul, 2008
    Hi,
    I tried the trick in the Q&A I mentioned above. But the only thing I got was the site name as subject. Maybe I did something wrong?

    This is what I did:

    I made a test form and in the Form HTML part of the form code tag i Chronoforms I wrote:
    <?php 
    $database->setQuery( "
      SELECT title 
        FROM #__content 
        WHERE id='".$_GET['id']."'" ); 
    $title = $database->loadResult(); 
    ?>
    <input type="text" name="text" />
    <input type="submit" name="submit" value="Submit" />
    {imageverification}
    And then I put this in the "On Submit code - before sending email":
    <?php 
    global $mainframe; 
    $rows[0]->emailsubject = $title; 
    ?>
    This returned an e-mail with the subject of the web site name and the content of the text field.

    I hope you can help me out on this. It would solve my problem if the page title could be returned instead. I think it's close now.

    Yours
    --Mats Arvendal
    arvendal 20 Jul, 2008
    Hi

    I have continued to investigate the code examples and I think I can make these conclusions:

    1. Both the codes:
    <?php 
    global $mainframe; 
    $rows[0]->emailsubject = $title; 
    ?>
    and
    <?php 
    global $mainframe; 
    $rows[0]->emailsubject = $mainframe->getPageTitle(); 
    ?>
    manage to collect the site name as e-mail subject (with or without the code below).

    2. The code
    <?php 
    $database->setQuery( " 
      SELECT title 
        FROM #__content 
        WHERE id='".$_GET['id']."'" ); 
    $title = $database->loadResult(); 
    ?>
    doesn't affect the way the e-mail subject is chosen, i.e. it doesn't seem to collect the page title instead of the site name. Could there be any syntax error in this code?

    I used Joomla 1.0.15 for this investigation.

    Btw, today I finally purchased the license for Chronoforms. I really like this extension and I have decided to use it on 2-3 different web sites.

    Yours sincerely,
    --Mats Arvendal
    GreyHead 20 Jul, 2008
    Hi Mats,

    A little digging got me to this
    <?php
    $menu = $mainframe->get( 'menu' );
    $params = new mosParameters( $menu->params );
    $title = $params->get( 'header' );
    ?>
    Bob
    arvendal 20 Jul, 2008
    Hi,

    thanks for all your effort. May I please just ask if you could specify what code to put where, i e what code should go in form code HTML field and On Submit code - before sending email field?

    Yours sincerely,
    --Mats Arvendal
    arvendal 20 Jul, 2008
    Sorry!

    I think I have given you some wrong information.
    The info that is returned as e-mail subject never seems to be Joomla site name, instead nothing is returned. The subject line is empty.

    Sorry if I confuse you!

    Yours
    --Mats Arvendal
    arvendal 20 Jul, 2008
    Forgot one thing:

    I wrote xxx as e-mail subject in the created form and that value seems always to be overwritten by all the different PHP codes I have used.

    Yours
    --Mats
    GreyHead 20 Jul, 2008
    Hi Mats,

    The only place that the page title is available is actually in the page so you need to identify this in the form html and pass it back for processing. Form Html:
    // some form code
    <?php 
    $menu = $mainframe->get( 'menu' ); 
    $params = new mosParameters( $menu->params ); 
    $page_title = $params->get( 'header' ); 
    ?>
    <input type="hidden" name="page_title" value="<?php echo $page_title; ?>" />
    and in the OnSubmit Before box
    <?php
    $rows[0]->emailsubject = $_POST['page_title'];
    ?>
    Bob
    arvendal 21 Jul, 2008
    Hi,

    I really hope you will not get tired of me...🙂

    This last code example really made it came more close to what I was hoping for. Near, but not quite there.

    The code generated a message that had the text from "page title" in Joomla's main menu item. Look at this screen shot of the result:

    Automatic input of document page title into form image 1

    I would like to catch the Title, "Ett ankhuvud" and turn that into a e-mail subject. (Ett ankhuvud is Swedish for "a duck head" - just an text title)

    Yours sincerely
    --Mats Arvendal
    arvendal 23 Jul, 2008
    Hi,

    Since I had only tried your code examples on a Joomla 1.0.15 site I began to wonder if there may be a difference if I use the latest Joomla version, therefore I installed Joomla 1.54 on my hosts server and added the codes to a Chronoform I made. But when the page containing the code:

    <!--Form HTML-->
    <?php 
    $menu = $mainframe->get( 'menu' ); 
    $params = new mosParameters( $menu->params ); 
    $page_title = $params->get( 'header' ); 
    ?>
    <input type="hidden" name="page_title" 
      value="<?php echo $page_title; ?>" />
    
    <!-- On Submit code - before -->
    <?php 
    $rows[0]->emailsubject = $_POST['page_title']; 
    ?>
    was opened in Explorer I only got the 500 server error message. When I cleaned the form from the code above, the page loaded all right.

    I hope you may be able to give me some advice on this question. The forms are meant to be used on a travel agency's website, where it would be very convenient to use the same form for all destinations, when the purpose is for the visitor to ask for more information on a specific destination.

    If there are more users who need this feature maybe it could be implemented in a future version of this fine and useful extension.

    Yours sincerely
    --Mats Arvendal
    GreyHead 23 Jul, 2008
    Hi Mats,

    I don't see why you'd get a server error with that code - though you may well be missing a global $mainframe; at the beginning.

    There are big differences between Joomla 1.0.x and Joomla 1.5.x in where some data is stored. My code was tested in 1.5 (I think).

    The problem we have so far here is not really a ChronoForms problem but finding the *right* data from Joomla to allow you to distinguish between the pages.

    Bob
    arvendal 23 Jul, 2008
    Thanks for your help.

    I have contacted my host to see if there's any problem with the server configuration.

    My template has the command
    <?php echo $mainframe->getCfg('sitename');?>
    so I can't understand why the $mainframe creates problem when I try to use it in the form.

    I will look around for a solution on how to retrieve the value of the Page title. If I find a solution I will let you know.

    Thanks for your effort. You are great.

    Yours
    --Mats Arvendal
    GreyHead 23 Jul, 2008
    Hi Mats,

    Sometimes PHP limits the scope of variables and they are not automatically availalbe to functions, eval blocks and include blocks.

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