jt782/require-read-terms-php

Display modal for "terms and conditions", and require user read (scroll to bottom) and agree to those terms before submitting form.

1.5.1 2022-04-24 01:46 UTC

README

Latest Version on Packagist Tests Total Downloads

Display modal for "terms and conditions", and require user read (scroll to bottom) and agree to those terms before submitting form.

Installation

You can install the package via composer:

composer require jt782/require-read-terms-php

Usage

  1. Initialize class with form target (e.g. ".class" or "#id") and terms content:
use Seven82Media\RequireReadTerms\FormTerms;

$terms = new FormTerms(
    '#target-form-id',
    '<p>terms go here</p>'
);
  1. You can modify the following values with these methods:
  • Agree Button Text: $terms->agreeButtonText("Yes, I agree!")
  • Agree Button Color: $terms->agreeButtonColor("green")
  • Cancel Button Text: $terms->cancelButtonText("NO, this is dumb!")
  • Cancel Button Color: $terms->cancelButtonColor("red")
  • Width: $terms->width("64em")
  1. Within the form, load content and display button:
$terms->loadModalDisplayButton()
  1. If you want more control of the placement of the button vs the script, you can load them separately:
  • For button display:
$terms->displayButton()
  • For script output:
$terms->loadScript()
  1. If you have a checkbox for agree to terms, you can hide it visually and have the package check it once the user has agreed to terms:
$terms->checkboxFieldTarget("#agree-to-terms");
?>
<div style="display:none;">
    <input type="checkbox" value="1" name="agreetoterms" id="agree-to-terms" />
</div>

Example

<?php
    $terms = new FormTerms('.test-form', '<p>Term content goes here</p>');
    $terms->checkboxFieldTarget("#agree-to-terms");
?>
<form class="test-form" method="get" action="/form">
    <?php
        $terms->loadModalDisplayButton();
    ?>

    <div style="display:none;">
        <input type="checkbox" value="1" name="agreetoterms" id="agree-to-terms" />
    </div>
    
    <p>
        <button type="submit">Submit</button>
    </p>
</form>

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.