Embed Form in Detail Page
The send inquiry feature in JReviews appears as a button in the listing detail pages when enabled. This opens a dialog allowing users to send a message.
If you prefer to display the form outright on the listing detail page it can be done by customizing the listing detail template.
-
Enable inquiries
Set Configuration Settings → Listings → Enable Listing Inquiries
to yes
or embed only
. Embed only hides the button, while allowing the form to be posted directly to the server.
-
Add the form to the detail template
Copy the listings/detail.thtml
template from the default theme to your custom theme and add the code below where you want to show the form in the layout. Remember to clear the file registry.
<?php
$permission = $this->perm->__('listing')->setListing($listing);
if ($permission->allowsInquiries() && $permission->canSendInquiry())
{
echo $this->element("inquiry_widget");
}
?>
It's possible to add more fields to the form using the inquiry_form_top
action hook. If some of these fields should be required, this can also be done using the inquiry_submit_validation
filter hook.
The example assumes you are already familiar with using hooks. Need a refresher on using hooks?
Clickfwd\Hook\Action::add('inquiry_form_top', function($params)
{
$Form = new FormHelper();
?>
<div class="jrFieldDiv">
<label for="jr-inquiry-phone">
<?php __t("Phone Number");?><span class="jrIconRequired"></span>
</label>
<?php echo $Form->text('data[Inquiry][phone]',[
'id'=>'jr-inquiry-phone',
'class'=>'jrText',
]);?>
</div>
<div class="jrFieldDiv">
<label for="jr-inquiry-checkbox_example">
<?php __t("Checkbox Example");?> <span class="jrIconRequired"></span>
</label>
<?php echo $Form->checkbox('data[Inquiry][checkbox_example]',
[
'one'=>'One',
'two'=>'Two',
'three'=>'Three'
],
[
'id'=>'jr-inquiry-checkbox_example',
'option_class'=>'jr-option jrFieldOption',
]
);?>
</div>
<div class="jrFieldDiv">
<label for="jr-inquiry-select_example">
<?php __t("Select Example");?>:
</label>
<?php echo $Form->select('data[Inquiry][select_example]',
[
''=>'Select Option',
'one'=>'One',
'two'=>'Two',
'three'=>'Three'
],$selected = '',
[
'id'=>'jr-inquiry-select_example',
'class'=>'jrSelect',
]
);?>
</div>
<div class="jrFieldDiv">
<label for="jr-inquiry-date_example">
<?php __t("Date Example");?>
</label>
<?php echo $Form->text('data[Inquiry][date_example]',[
'id'=>'jr-inquiry-date_example',
'class'=>'jrDate jr-date'
]);?>
</div>
<?php
});
The required icon is output using <span class="jrIconRequired"></span>
, but this doesn't make the fields required. To do that we use the validation filter below where you can add or remove entries from the $required
array. For each array entry the key is the input name, and the value is the label used in the validation message.
Clickfwd\Hook\Filter::add('inquiry_submit_validation', function($validation, $params)
{
$required = [
'phone' => 'Phone Number',
'checkbox_example' => 'Checkbox Example',
'select_example' => 'Select Example',
];
foreach($required as $key => $text)
{
$found = S2Array::get($params,"data.Inquiry.{$key}");
if ( !$found )
{
$validation[] = "{$text} is required";
}
}
return $validation;
}, 10);
If you have the option to store inquiries enabled, new fields added using the above example will be automatically stored and visible in the administration. However, the fields will not be automatically included in emails. To include them you can use the inquiry_email_extra_fields
action hook as shown below.
Clickfwd\Hook\Action::add('inquiry_email_extra_fields', function($extra_fields, $params)
{
$fieldLabels = [
'phone' => 'Phone Number',
'checkbox_example' => 'Checkbox Example',
'select_example' => 'Select Example',
'date_example' => 'Date Example'
];
if (empty($extra_fields))
{
return;
}
foreach ($extra_fields as $key => $value):
?>
<p><?php echo $fieldLabels[$key]; ?>: <?php echo is_array($value) ? implode(', ',$value) : $value; ?></p>
<?php
endforeach;
});