Skip to content

padmedia/Stamp-Duty-Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Stamp Duty Calculator plugin for Craft CMS

This plugin allows you to adda Stamp Duty calculator to your Craft CMS 2 website.

Installation

To install Stamp Duty Calculator, follow these steps:

  1. Upload the stampdutycalculator/ folder to your craft/plugins/ folder
  2. Go to Settings > Plugins from your Craft control panel and enable the Stamp Duty Calculator plugin.

Usage

{% macro errorList(errors) %}
    {% if errors %}
        <ul class="errors">
            {% for error in errors %}
                <li>{{ error }}</li>
            {% endfor %}
        </ul>
    {% endif %}
{% endmacro %}

{% from _self import errorList %}

<form method="post" action="" accept-charset="UTF-8">

		{{ getCsrfInput() }}

		<input type="hidden" name="action" value="stampDutyCalculator/calculate">
		<input type="hidden" name="redirect" value="results/page">

		<label for="propertyValue">Property Value (£)</label>
		<input type="text" name="propertyValue" id="propertyValue" class="number" minlength="4" maxlength="10" required>
		{{ error is defined and error ? errorList(error.getErrors('propertyValue')) }}

		<label for="purchaseType">Purchase Type:</label>
		<select name="purchaseType" id="purchaseType" required>
			<option value="singleProperty">Sole Property</option>
			<option value="additionalProperty">Additional Property</option>
			<option value="firstTimeBuyer">First Time Buyer</option>
		</select>

		<button type="submit">Calculate</button>

</form>

"propertyValue" and "purchaseType" are both required fields.

Redirecting after submit

If you have a ‘redirect’ hidden input, the user will get redirected to it upon successfully calculating the stamp duty. The following variable can be used within the URL/path you set:

  • {stampDuty}

For example, if you wanted to redirect to a “results” page and pass the stamp duty to it, you could set the input like this:

<input type="hidden" name="redirect" value="results?sdlt={stampDuty}">

On your results.html template, you can access that ‘sdlt‘ parameter using craft.request.getQuery():

<p>Your stamp duty would be {{ craft.request.getQuery('sdlt') }}!</p>

Note that if you don’t include a ‘redirect’ input, the current page will get reloaded and the following variable will be defined

  • {{ stampDuty }}

For example:

{% if stampDuty is defined %}
	{{ stampDuty }}
{% endif %}

Ajax form submissions

You can optionally post the stamp duty calculator submissions over Ajax if you’d like. Just send a POST request to your site with all of the same data that would normally be sent:

var $sdltCalc = $('#stampDutyCalculator');

$sdltCalc.submit(function(e) {

	// Remove existing Messages
	$('.sdltError,.sdltResult').remove();

	// Get the post data
	var data = $(this).serialize();

	$.post('/', data, function(response) {

		if (response.success) {
			$sdltCalc.append('<div class="sdltResult"><p>Stamp Duty: <strong>' + response.stampDuty + '</strong></p></div>');
		} else {
			$sdltCalc.append('<div class="sdltError"><p>Sorry, an error occured. Please try refreshing the page.</p></div>')
		}

	});

});

About

Calculates UK Stamp Duty within Craft CMS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages