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.
Fund package maintenance!
jt782
Requires
- php: ^7.4|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- pestphp/pest: ^1.20
README
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
- 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>' );
- 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")
- Within the form, load content and display button:
$terms->loadModalDisplayButton()
- 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()
- 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.