2

I'm using the "legal" module version 6.x-8.5. This is a great module, but i think there's a form_set_error() message needed, to show the user which's trying to register, why registering cannot be applied, if he forget to click the required checkbox(es). I'm looking for a possibility to get this working. Does anybody know where to implement this function(hardcoded, if there isn't a other solution) in the module? I also tried to do this with rules forms, with this rule:

    array (
  'rules' => 
  array (
    'rules_register_ckeck_agb' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_register_form_validate',
      '#label' => 'Register ckeck AGB',
      '#active' => 0,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#settings' => 
          array (
            'element' => 'legal[legal_accept]',
            'value' => '1',
                '#argument map' => 
            array (
              'form' => 'form',
              'form_state' => 'form_state',
            ),
          ),
          '#type' => 'condition',
          '#name' => 'rules_forms_condition_element_value',
          '#info' => 
          array (
            'label' => 'Form element \'legal[legal_accept]\' value check',
            'arguments' => 
            array (
              'form' => 
              array (
                'type' => 'form',
                'label' => 'Formular',
              ),
              'form_state' => 
              array (
                'type' => 'form_state',
                'label' => 'Form state',
              ),
              'element' => 
              array (
                'type' => 'string',
                'label' => 'Form element ID',
                'description' => 'ID of the form element to be targeted. Examples on the "Create Story" form: "title" for the title field or "body_field[body]" for the body field.',
              ),
              'value' => 
              array (
                'type' => 'string',
                'label' => 'Value(s)',
                'description' => 'Value(s) assigned to the form element. If the form element allows multiple values, enter one value per line.',
              ),
            ),
            'module' => 'Rules Forms',
          ),
          '#weight' => 0,
          '#negate' => 1,
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'label' => 'Set form error on element \'legal[legal_accept]\'',
            'arguments' => 
            array (
              'form' => 
              array (
                'type' => 'form',
                    'label' => 'Formular',
              ),
              'element' => 
              array (
                'type' => 'string',
                'label' => 'Form element ID',
                'description' => 'The element that should be marked. Examples on the "Create Story" form: "title" for the title field or "body_field[body]" for the body field.',
              ),
              'message' => 
              array (
                'type' => 'string',
                'label' => 'Nachricht',
                'description' => 'The message that should be displayed to the user.',
              ),
            ),
            'module' => 'Rules Forms',
          ),
          '#name' => 'rules_forms_action_set_error',
          '#settings' => 
          array (
            'element' => 'legal[legal_accept]',
            'message' => 'Please Confirm the...',
            '#argument map' => 
            array (
              'form' => 'form',
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
  ),
)

But this also does not the job, it should do. Does anybody know what I'm maybe doing wrong here? Thanx for all your suggestions. regards dennis605

1

I've posted my reply to you problem in the Legal issue you created.

I'll go over how you would create an additional validation that will throw a form_set_error()

Create a custom module with this

function example_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'user_register') {
      $form['legal']['legal_accept']['#element_validate'] = array('_example_custom_field_validate');
    }
}

function _example_custom_field_validate($element, &$form_state) {
   if (empty($element['#value'])) {
     form_error($element, t('This is my custom message if `Terms & Conditions` is not checked off.'));
   }
}

custom form error message

If you don't see the message now, I am worried that you have error messages turned off.

  • works like a charm! Thanks for your support! That's exactly what i was looking for. – dennis605 Jul 18 '11 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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