JReviews logo
Guides My site
← All guides Community guide

Add, validate, and email extra inquiry fields

Alejandro
Thread started by Alejandro. Contributors Alejandro.
Thread started
Last updated

What you’ll achieve

Add phone, checkbox, select, and date inputs to the inquiry form and include their values in the email.

My site

Platform
JReviews version

Add a phone number, checkbox choices, a select field, and an optional date to the inquiry form. Include the submitted values in the inquiry email.

Prepare the field names and PHP file

This example collects a phone number, checkbox choices, a selected option, and an optional date. The values belong to the inquiry, so you do not need matching listing custom fields. Keep each field name consistent between form, validation, and email output.

Enable listing inquiries in Configuration Settings → Listings and use a listing with an inquiry recipient. Open its inquiry button before adding the fields. The form must already send an ordinary inquiry successfully.

Start a new PHP file with <?php followed by defined('MVC_FRAMEWORK') or die;. If the file already exists, keep its opening tag and guard.

JReviews 6 Early Access

Add inputs and validation

Open JReviews → Configuration → Early Access Settings. Enable Listing Detail Page for the inquiry form. Before copying the callbacks below, prepare the email path:

  1. Open JReviews → Configuration → Cron. Copy your installation's Cron URL and substitute its Cron Secret. Use the URL shown by your own installation.
  2. Open that URL and confirm Cron ran successfully. Configure your hosting scheduler to request it every minute, following the JReviews cron setup. Disable Run on site visits after the scheduled cron works.
  3. Enable Email Notifications in Early Access. This switch is independent of Listing Detail Page. Inquiries wait in a mail queue until the scheduled cron sends them.
  4. Send an ordinary inquiry before adding the callbacks. Wait for processing and confirm that the intended recipient receives it with Email Notifications enabled.

A successful form submission alone does not confirm email delivery. Continue after this email path works.

Joomla. Use templates/jreviews_overrides/hooks.php.

WordPress. Use jreviews_overrides/hooks.php.

Add both callbacks below to the override file. The first, marked with +, adds the form fields. The second checks required entries, allowed choices, and the date format before the inquiry is accepted.

  • If hooks.php already exists, add the marked lines at the end of the file. The copy button copies only those lines.
  • If you are creating hooks.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;

fwd_add_action('jreviews:listing_inquiry_form.bottom', function ($listing, $creating) {
	$values = fwd_request()->input('inquiry.extra_fields', []);
	$values = is_array($values) ? $values : [];
	$escape = static function ($value): string {
		return htmlspecialchars(is_scalar($value) ? (string) $value : '', ENT_QUOTES, 'UTF-8');
	};
	$errors = fwd_view()->shared('errors');
	$showErrors = static function (string $key) use ($errors, $escape): void {
		if (! $errors) { return; }
		$messages = $errors->get('inquiry.extra_fields.'.$key);
		array_walk_recursive($messages, static function ($message) use ($escape): void {
			echo '<p role="alert">'.$escape($message).'</p>';
		});
	};
	echo '<label>Phone <input name="phone" type="tel" required value="'.$escape($values['phone'] ?? '').'"></label>';
	$showErrors('phone');
	echo '<fieldset><legend>Choices</legend>';
	$selected = is_array($values['checkbox_example'] ?? null) ? $values['checkbox_example'] : [];
	foreach (['one' => 'One', 'two' => 'Two', 'three' => 'Three'] as $value => $label) {
		echo '<label><input type="checkbox" name="checkbox_example[]" value="'.$value.'"'.(in_array($value, $selected, true) ? ' checked' : '').'>'.$label.'</label>';
	}
	echo '</fieldset>';
	$showErrors('checkbox_example');
	$showErrors('checkbox_example.*');
	echo '<label>Option <select name="select_example" required><option value="">Select</option>';
	foreach (['one' => 'One', 'two' => 'Two', 'three' => 'Three'] as $value => $label) {
		echo '<option value="'.$value.'"'.(($values['select_example'] ?? null) === $value ? ' selected' : '').'>'.$label.'</option>';
	}
	echo '</select></label>';
	$showErrors('select_example');
	echo '<label>Date <input name="date_example" type="date" value="'.$escape($values['date_example'] ?? '').'"></label>';
	$showErrors('date_example');
}, 20, 2);
fwd_add_action('jreviews:listing_inquiry_form.validation', function ($validator, $creating) {
	$validator->addRules([
		'inquiry.extra_fields.phone' => ['required', 'string', 'max:80'],
		'inquiry.extra_fields.checkbox_example' => ['required', 'array', 'min:1'],
		'inquiry.extra_fields.checkbox_example.*' => ['string', 'in:one,two,three'],
		'inquiry.extra_fields.select_example' => ['required', 'in:one,two,three'],
		'inquiry.extra_fields.date_example' => ['nullable', 'date_format:Y-m-d'],
	]);
}, 20, 2);

Phone validation limits text length without assuming a country-specific format. The date is optional and accepts YYYY-MM-DD. The server also checks the allowed selection values.

The inputs restore submitted values and display server validation errors when the form opens again. To explain what happens after submission, add a paragraph to the same form callback before the phone input:

echo '<p>We send your message to the listing owner, who can contact you using the details you provide.</p>';

Use wording that matches your site's inquiry process.

Include the values in the email

With Email Notifications enabled and the cron and ordinary-inquiry delivery checks complete, add this callback after the form callbacks in hooks.php. It prints submitted values in the email. If you rename a form field, change the matching name here too, such as phone in both places:

fwd_add_action('jreviews:listing_inquiry_email.extra_fields', function ($extraFields, $listing) {
	foreach (['phone' => 'Phone', 'checkbox_example' => 'Choices', 'select_example' => 'Option', 'date_example' => 'Date'] as $key => $label) {
		if (!array_key_exists($key, $extraFields)) {
			continue;
		}
		$value = $extraFields[$key];
		$value = is_array($value) ? implode(', ', array_filter($value, 'is_scalar')) : $value;
		if (!is_scalar($value)) {
			continue;
		}
		echo '<p>'.htmlspecialchars($label, ENT_QUOTES, 'UTF-8').': '.htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8').'</p>';
	}
}, 20, 2);

JReviews 5 and v6 Legacy

Add inputs, validation, and email output

Joomla. Use templates/jreviews_overrides/filters/filter_functions.php.

WordPress. Use jreviews_overrides/filters/filter_functions.php.

Add the code marked with +. It adds the form fields, checks that required fields are filled in, and includes their values in the email.

  • If filter_functions.php already exists, add the marked lines at the end of the file. The copy button copies only those lines.
  • If you are creating filter_functions.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;

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
});

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);

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):
	?>
		<?php if (!isset($fieldLabels[$key])) { continue; } ?>
		<p><?php echo htmlspecialchars($fieldLabels[$key], ENT_QUOTES, 'UTF-8'); ?>: <?php echo htmlspecialchars(is_array($value) ? implode(', ', array_filter($value, 'is_scalar')) : (is_scalar($value) ? (string) $value : ''), ENT_QUOTES, 'UTF-8'); ?></p>
	<?php
	endforeach;
});

Rename the input, $required key, and $fieldLabels key together. Remove a field from $required to make it optional. This legacy validation checks whether a value was entered. It does not check the phone or date format, or whether a selected option is allowed. Add explanatory HTML inside inquiry_form_top when needed.

Test the complete inquiry

Submit once with required values missing, then submit with a complete phone number, multiple checkboxes, a selected option, and an optional date. Confirm that required-field errors appear and the final email contains the submitted values as text, without treating any entered HTML as email formatting.

JReviews 6 Early Access. Also submit invalid selection values and an invalid date. Confirm that validation rejects them and restores the entered values when the form reopens. For a valid submission, use phone +1 312 555 0101, choices One and Three, option Two, and date 2026-11-15. After queue processing, the received email must contain Phone: +1 312 555 0101, Choices: one, three, Option: two, and Date: 2026-11-15. The choice labels on the form differ from the saved values printed in this example.

JReviews 5 and v6 Legacy. The supplied validation checks presence only. It does not reject a disallowed option or invalid date format. Check the form after a rejected submission before relying on restored input values.

See Inquiry Form Customizations, especially Extra Fields in Email.

For list-page button placement, use the Inquiry action guide.

Learn more