Drupal 5: Adding terms and conditions to the user registration form
The following will show you how to add a terms and conditions form element and admin settings page to display a required terms and conditions form element on the user registration form. First, I added an admin settings page.
<?php
function MYMODULE_admin_settings_form() {
$form = array();
// ...code...
$form['MYMODULE_terms_conditions'] = array(
'#type' => 'textarea',
'#title' => t('Terms and Conditions'),
'#default_value' => variable_get('MYMODULE_terms_conditions', ''),
'#required' => FALSE,
);
// ...code...
return system_settings_form($form);
}
?>
Next I modified the user registration form.
<?php
function MYMODULE_form_alter($form_id, &$form) {
// ...code...
if ($form_id == 'user_register') {
$terms = variable_get('MYMODULE_terms_conditions', '');
if (strlen($terms)) {
// add terms and conditions
$form['terms'] = array(
'#type' => 'checkbox',
'#required' => TRUE,
'#weight' => 9,
'#title' => "I agree to the <a id='termsAndConditionsLink'>terms and conditions</a><div style='display:none;' id='termsAndConditionsText'>$terms</div>",
);
}
}
// ...code...
}
?>
Last I added some jQuery to my module’s javascript include file.
$(document).ready(function(){
$('a#termsAndConditionsLink').click(function() {
if ($('div#termsAndConditionsText').css('display') == 'none') {
$('div#termsAndConditionsText').slideDown();
} else {
$('div#termsAndConditionsText').slideUp();
}
});
});