Make it mandatory for new users to agree to terms and conditions before signing up

I got a question from an AppGini user on how to make it a requirement for users to check an ‘I agree’ box when they sign up to AppGini — possibly as part of GDPR compliance, or to agree to some other terms and conditions.

We do plan to add support for this as part of future versions of AppGini. However, for now it can be done through a quick JavaScript code customization in hooks/footer-extras.php. The steps in brief are: check if the current page is the signup page, and if so, change custom field #4 to a checkbox, and prevent form submission if the box is unchecked.

The steps above make use of one of the custom user fields and turn it into a checkbox. In AppGini, the user profile supports storing up to 4 customizable fields. If you follow the steps here, one of them will be used for the checkbox, so you’ll have only 3 left. It’s a caveat but can be used as a work-around for now till we implement it as a separate feature in AppGini. So, the code to be placed in hooks/footer-extras.php would look like this:

	$j(function() {
		// if this is not the signup page, don't continue
		if(! /membership_signup\.php/.test(location.href)) return;

		// change custom4 field to a checkbox
			.attr('type', 'checkbox')
			.wrap('<div class="checkbox"><label></label></div>')
			.after('I agree to <a href="hooks/terms.php">terms and conditions</a>');

		// make the checkbox mandatory
		$j('form').submit(function() {
			if(!$j('#custom4').prop('checked')) {
				alert('Sorry .. must agree to sign up!');
				return false;

You could change the wording of the checkbox by editing line 12 above. Also, you could change the error message by changing line 17. You’ll need to add a file containing the terms and conditions in the hooks folder, naming it terms.php. It might look something like this:

	define('PREPEND_PATH', '../');
	$hooks_dir = dirname(__FILE__);

<div class="page-header"><h1>Terms and conditions</h1></div>

	<li> Condition 1 here</li>
	<li> Condition 2 here</li>
	<li> More terms here</li>
<?php include_once("{$hooks_dir}/../footer.php"); ?>

Change the wording above as you see fit. Please let me know if you have any questions or comments.

Published by Genedy

I'm the founder of BigProf Software. We're a tiny team of developers who create tools that make it easy (and affordable) for anyone to create connected business applications that work from any device with a browser.

Leave a comment

Your email address will not be published. Required fields are marked *