Send an email to the entry's owner through an RSForm!Pro form
In this article we will describe the process of implementing a functionality which will enable frontend users to send a message (via email) to the visited entry's author using an RSForm!Pro form.
Displaying the form on the entry's page
Assuming that you have already created the form along with the fields required for your exact scenario (for example: full name, email, subject - text boxes, message - a text area) and authoremail - a hidden field which will be filled in with the author's email by our cusotm PHP script, here's what you need to do in order to display the RSForm!Pro form on the entry's page:
The RSForm!Pro System plugin
To display an RSForm!Pro form anywhere on your website, you will need to first install and enable the RSForm!Pro System Plugin. Then, simply add the following syntax where you want the form to be displayed:
{rsform x}
where x is the form's ID.
Template overrides
As there is no integration available between RSDirectory! and RSForm!Pro, adding that syntax on all entries pages is only possible through the use of custom PHP scripts and template overrides:
The file that controls the single entry view is called default.php and it's located in:
\components\com_rsdirectory\views\entry\tmpl
The RSForm!Pro - specific syntax needs to be added in this file. We could perform the modifications in the file found under this path, and the changes will take effect. However, upon a possible future update of the component, the file will be overwritten and your customization will be lost. This is where the concept of template overrides comes in.
Joomla! offers the possibility to avoid losing this type of modifications by creating a copy of the file which is to be modified in the default frontend template's html folder:
/templates/template_name/html/
In order for Joomla! to recognize which component's view the file belongs to, you will need to replicate a part of the folder structure the file originates from. Please create the following folders under the path provided above:
/templates/template_name/html/com_rsdirectory/entry/
and copy the default.php file here.
Assuming that your form's ID is 1, please add the following code and syntax where you want to have to form displayed on an individual entry's page:
<div>{rsform 100}</div>
Important: Make sure to replace 100 with the actual ID of your form (you can find it in the Components >> RSForm!Pro >> Manage Forms area).
The custom PHP code
Head to Components >> RSForm!Pro >> Manage Forms >> edit your form >> Properties >> PHP Scripts and add the following code in the Script called on form process area:
$entryid= Joomla\CMS\Factory::getApplication()->input->getInt('id'); //returns the entry's id from the URL $db = Joomla\CMS\Factory::getDBO(); //opens a database connection $db->setQuery("SELECT `user_id` FROM #__rsdirectory_entries WHERE `id`='$entryid'"); //query that gets the author's id from the database based on the entry's id $result=intval($db->loadResult()); //converts the result returned by the query in an integer if($result){ $owner = Joomla\CMS\Factory::getUser($result); //creates an object containing information on the entry's author $_POST['form']['authoremail']=$owner->email; //adds the author's email address in the form's hidden field. }
All you need to do now is head to Components >> RSForm!Pro >> Manage Forms >> edit your form >> Properties >> User Emails and add the hidden field's {name_of_your_hidden_field:value} placeholder in the email's To field. In our example, as mentioned earlier, the hidden field's name is authoremail and it's value will be automatically completed by our custom PHP script with the author's email address. By adding its value placeholder in the email's To field will render the email to be sent to that address. The final result should look like this:
{authoremail:value}
You can read more on configuring RSForm!Pro emails in this dedicated article.
4 persons found this article helpful.
You Should Also Read
Contact the website admin using an RSForm!Pro form (+entry title) |