Get the page title

To get the page title of page inside a field you require a simple script. This can be done through PHP or JavaScript. Examples:

Through PHP

Placed in the Default Value area of a field. This can be particularly useful when using the form inside a module or inside an article and you wish to know from where it was submitted:

Don't forget to use the <code> tags within the Default Value field!
$doc = JFactory::getDocument();
return $doc->getTitle();

Through JavaScript

This scenario assumes the use of two form components, a hidden field component and a freetext component. You should place the following script within a freetext:

<script type="text/javascript">
document.getElementById('hidden_field_name').value = document.title;

For the script to work properly you will have to replace hidden_field_name with your hidden field component exact name. When the form is submitted, the page title will be stored in the hidden field (the page title will not show within the form in the frontend area).

We recommend adding this freetext component as the last component of your form. Adding it before the hidden field will prevent the script from working.

15 persons found this article helpful.

Was this article helpful?

Yes No
Sorry about that