You are here

function rules_forms_action_set_default in Rules Forms Support 7

Action: Set the default value of a form element.

Parameters

mixed $form: A reference to the form array of the form for which the event was triggered.

string $element: The element ID of the element being checked in the form of element_type:element_id.

string $value: A value to assign to the form element. If the form element uses #options then the value is split into an array.

1 string reference to 'rules_forms_action_set_default'
rules_forms_rules_action_info in ./rules_forms.rules.inc
Implements hook_rules_action_info().

File

includes/rules_forms.eval.inc, line 362
Evaluation functions for Rules Forms module.

Code

function rules_forms_action_set_default($form, $element, $value) {
  $form_element =& _rules_forms_get_element($form, $element);

  // Try to determine if this is a multiple option element.
  if (isset($form_element['#type']) && isset($form_element['#options'])) {
    switch ($form_element['#type']) {
      case 'checkboxes':
        $multiple = TRUE;
        break;
      case 'select':
      case 'tableselect':
        if (isset($form_element['#multiple']) && $form_element['#multiple']) {
          $multiple = TRUE;
        }
    }
  }
  $form_element['#default_value'] = isset($multiple) ? explode("\r\n", $value) : $value;
}