1

And also, how can I get node/terms to open target="_blank"?

<?php


function MYMODULE_form_alter(&$form, $form_state, $form_id) {
    if($form_id == 'user_register') {
  $form['legal'] = array(
      '#type' => 'fieldset',
      '#title' => t('legal'),    
    );
  $form['legal']['select'] = array(
      '#type' => 'checkbox',
      '#required' => TRUE,
      '#title' => t('Terms of Use<span class="form-required" title="' . t('This field is required') . '">*</span>'),
      '#default_value' => 0,
      '#description' => t('I certify that I am over the age of 18, and I have read and agree to the '.l('Terms of use.','node/terms').''),     
    );   
  $form['#validate'][] ='customfunctions_form_validate_custom';
  }  

}  



function MYMODULE_form_validate_custom($form, &$form_state) {
    $legal = $form_state['values']['select'];  
    if ($legal == 0) {
        form_set_error('select', 'Please check the agreement.');
    }
}


?>
7
  • You know there is a module for just this. drupal.org/project/legal Commented Jul 11, 2011 at 13:34
  • Why use a module when a few lines of code will do?
    – Joe
    Commented Jul 11, 2011 at 13:36
  • +1 @ Jeremy French, however I think he just needs a checkbox to the form, whereas, legal module will a separate term of use page.
    – iStryker
    Commented Jul 11, 2011 at 13:38
  • Legal handles things like changing T&Cs. Nothing to stop you rolling your own if you want to. Commented Jul 11, 2011 at 13:39
  • iStryker is right. I am just making sure my code is correct. I feel like I am missing something.
    – Joe
    Commented Jul 11, 2011 at 13:43

1 Answer 1

0

Yes, but I would change

$form['#validate'][] ='customfunctions_form_validate_custom';

to

$form['#validate'][] ='MYMODULE_user_registration_form_validate';

and

function MYMODULE_form_validate_custom($form, &$form_state) {

to

function MYMODULE_user_registration_form_validate($form, &$form_state) {

Nothing wrong with your code, but this just keep with the Drupal naming convention ie search_form_validate, node_form_validate, etc

Also

'#title' => t('Terms of Use<span class="form-required" title="' . t('This field is required') . '">*</span>'),

is bad

'#title' => t('Terms of Use') . "<span class='form-required' title='" . t('This field is required') . "'>*</span>",
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.