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 = Joomla\CMS\Factory::getDocument();
return $doc->getTitle();

Through JavaScript

This scenario assumes the use of two form components, a hidden field component and a JavaScript code. You should place the following script within your form's dedicated area, more precisely, under Form Properties > JavaScript while editing the form:

<script type="text/javascript">
window.onload = function(){
  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).

27 persons found this article helpful.

Was this article helpful?

Yes No
Sorry about that