You are here

function webform_pre_render_input_vars in Webform 7.4

Checks the number of input form elements on this page.

This ensures that the PHP max_input_vars limit is not exceeded.

Install this function as a #pre_render function.

1 string reference to 'webform_pre_render_input_vars'
webform_input_vars_check in ./webform.module
Check if the last form submission exceeded the servers max_input_vars limit.

File

./webform.module, line 5497
This module provides a simple way to create forms and questionnaires.

Code

function webform_pre_render_input_vars($element) {

  // Determine the limit on input vars for this server configuration.
  $limit = ini_get('max_input_vars');
  if ($limit) {

    // Estimate the number of input vars needed to see if the PHP limit has been
    // exceeded. Additional input_vars: op.
    $count = 1 + webform_count_input_vars($element);
    if ($count > $limit * 0.95) {
      $subs = array(
        '@count' => $count,
        '@limit' => $limit,
      );
      $warning = array(
        '#markup' => '<div class="messages warning">' . (user_access('administer site configuration') ? t('This form contains @count input elements. PHP max_input_vars is @limit and should be increased.', $subs) : t('This form may be too long to work properly. Contact the administrator.')) . '</div>',
        '#weight' => -1,
      );
      if ($element['#input_var_waring_parent']) {
        $element[$element['#input_var_waring_parent']]['input_vars_warning'] = $warning;
      }
      else {
        $element['input_vars_warning'] = $warning;
      }
      watchdog('webform', 'Page contains @count input elements but PHP max_input_vars is only @limit. Increase max_input_vars.', $subs, WATCHDOG_ERROR);
    }
  }
  return $element;
}