How to create a contact form on the property page using RSForm!Pro

This guide explains how to configure an RSForm!Pro form to send the Admin Email to the owner of an RSBooking property.

Step 1. Create a Hidden Field

In your RSForm!Pro form, create a Hidden Field named property_id


Step 2. Add the PHP Email Script

Go to Form Properties > PHP Email Scripts > Script called before the Admin Email is sent and add the following code:

$propertyId = (int) $_POST['form']['property_id'];

if ($propertyId) {
    $db = \Joomla\CMS\Factory::getDbo();

    $query = $db->getQuery(true)
        ->select($db->quoteName('created_by'))
        ->from($db->quoteName('#__rsbooking_properties'))
        ->where($db->quoteName('id') . ' = ' . (int) $propertyId);

    $db->setQuery($query);

    $ownerId = (int) $db->loadResult();

    if ($ownerId) {
        $owner = \Joomla\CMS\Factory::getUser($ownerId);

        if (!empty($owner->email)) {
            $adminEmail['to'] = $owner->email;
        }
    }
}

When the form is submitted, the script retrieves the property's owner (the one found in Components > RSBooking! > Properties > Edit the property > Publishing tab > Hosted by) and sends the Admin Email directly to that user.

 

Scenario 1: Using the RSForm!Pro System Plugin

If you are displaying the form directly in the property description using the RSForm!Pro System Plugin syntax, {rsform x} (whereas x is the id of the form), you will need to add the following code in the Hidden Field:

//<code> 
return \Joomla\CMS\Factory::getApplication()->getInput()->getInt('id', 0); 
//</code>
 

Scenario 2: Using the RSForm!Pro Modal Plugin

When the form is loaded through the RSForm!Pro Modal Plugin, it is displayed inside an iframe. Because of this, the property ID is no longer available automatically and must be passed to the form manually.

Thus, the Hidden Field can be left empty. Now, click on the RSForm!Pro Modal button in the Property Description and select the desired form. Use the Prefill Form Values option to populate the property_id hidden field with the current property's ID. Furter info on this topic here.

The RSForm!Pro Modal Plugin is commercial and needs to be purchased separately. You can buy it by accessing Customer Area > My memberships > Active Memberships > clicking the 'Buy Extra Plugins' button of your RSForm!Pro license.

 

Was this article helpful?

Yes No
Sorry about that