? maxlength-466396.patch
? maxlength-profile.patch
? maxlength_multistep.patch
Index: maxlength.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/maxlength/maxlength.module,v
retrieving revision 1.11.4.11.2.5
diff -u -p -r1.11.4.11.2.5 maxlength.module
--- maxlength.module	6 Jun 2009 16:35:30 -0000	1.11.4.11.2.5
+++ maxlength.module	6 Jun 2009 17:47:56 -0000
@@ -51,6 +51,10 @@ function maxlength_form_alter(&$form, &$
     variable_del(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] .'_js');
     variable_del(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] .'_text');
   }
+
+  elseif ($form_id == 'profile_field_form') {
+    _maxlength_profile_form_alter($form, $form_state);
+  }
 }
 
 function _maxlength_content_form_alter(&$form, &$form_state, $form_id) {
@@ -153,6 +157,101 @@ function _maxlength_cck_form_submit($for
   variable_set(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] .'_text', $form['#post'][MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] .'_text']);
 }
 
+function _maxlength_profile_form_alter(&$form, $form_state) {
+  //dsm($form);
+  // only allow this feature of type: textfield, textarea
+  $fid = isset($form['fid']['#value']) ? $form['fid']['#value'] : 0;
+  $type_enabled = FALSE;
+  if (arg(3) == 'add' && in_array($form['type']['#value'], array('textfield', 'textarea'))) {
+    $type_enabled = TRUE;
+  }
+  else {
+    $edit = db_fetch_array(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
+    $type_enabled = in_array($edit['type'], array('textfield', 'textarea'));
+  }
+
+  // load the config
+  // @TODO this lines can be done much cleaner.
+  if ($type_enabled) {
+    $value = array();
+    if (arg(3) == 'add') {
+      $value = array();
+      $value['enabled'] = FALSE;
+      $value['js'] = FALSE;
+      $value['text'] = 'Content limited to !limit characters, remaining: <strong>!remaining</strong>';
+    }
+    else {
+      $value = array();
+      $value['enabled'] = variable_get(MAXLENGTH_NODE_TYPE .'_profile_'. $fid .'_limit', 0) > 0;
+      $value['limit'] = variable_get(MAXLENGTH_NODE_TYPE .'_profile_'. $fid .'_limit', 0);
+      $value['js'] = variable_get(MAXLENGTH_NODE_TYPE .'_profile_'. $fid .'_js', FALSE);
+      $value['text'] = variable_get(MAXLENGTH_NODE_TYPE .'_profile_'. $fid .'_text', 'Content limited to !limit characters, remaining: <strong>!remaining</strong>');
+
+    }
+
+    $form['fields'][MAXLENGTH_NODE_TYPE .'_profile'] = array(
+      '#type' => 'fieldset',
+      '#weight' => $weight,
+      '#title' => t('Limit !type length', array('!type ' => $label)),
+      '#collapsible' => TRUE,
+      '#collapsed' => $value['enabled'],
+    );
+
+    $form['fields'][MAXLENGTH_NODE_TYPE .'_profile'][MAXLENGTH_NODE_TYPE .'_profile'] = array(
+      '#type' => 'textfield',
+      '#title' => t('!label max length', array('!label' => ucwords($label))),
+      '#field_suffix' => t('characters'),
+      '#return_value' => 1,
+      '#size' => 4,
+      '#default_value' => $value['enabled'],
+      '#description' => t('Maximum number of characters allowed for the !type field of this content type. Leave blank for an unlimited size.', array('!type' => $label)) .'<br/>'.
+      '<b>'. t('Please remember, it counts all characters, including HTML, so may not work as expected with rich text editors e.g. FCKeditor / tinyMCE.') .'</b>',
+        );
+    $form['fields'][MAXLENGTH_NODE_TYPE .'_profile'][MAXLENGTH_NODE_TYPE .'_profile'.'_js'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Enable remaining characters countdown for the !label', array('!label' => ucwords($label))),
+      '#default_value' => $value['js'],
+      '#description' => t('This will enable a Javascript based count down, as well as the client side validation for the !type field of this content type. If no limit set this is ignored.', array('!type' => $label)),
+    );
+    $form['fields'][MAXLENGTH_NODE_TYPE .'_profile'][MAXLENGTH_NODE_TYPE .'_profile'.'_text'] = array(
+      '#type' => 'textarea',
+      '#title' => t('!label count down message', array('!label' => ucwords($label))),
+      '#default_value' => $value['text'],
+      '#description' => t('The text used in the Javascript message under the !type input, where "!limit" and "!remaining" are replaced by the appropriate numbers.', array('!type' => $label)),
+    );
+    $form['#submit'][] = '_maxlength_profile_form_submit';
+  }
+}
+
+function _maxlength_profile_form_submit($form, &$form_state) {
+  // if we edit a field
+  if ($fid = $form_state['values']['fid']) {
+  }
+  else {
+    $fid = '';
+  }
+  dsm($fid);
+
+  $values = array();
+  $values['limit'] = $form_state['values'][MAXLENGTH_NODE_TYPE .'_'. $fid .'_'. 'profile_'.'limit'];
+  $values['js']    = $form_state['values'][MAXLENGTH_NODE_TYPE .'_'. $fid .'_'. 'profile_'.'js'];
+  $values['text']  = $form_state['values'][MAXLENGTH_NODE_TYPE .'_'. $fid .'_'. 'profile_'.'text'];
+
+  // get last fid if fid is not set
+  if ($fid == '') {
+    $fid = db_result(db_query("SELECT fid FROM {profile_fields} WHERE "));
+  }
+
+  dsm($values);
+  dsm($fid);
+  dsm($form_state);
+
+  //variable_set(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'], $form['#post']['max_length']);
+  //variable_set(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] .'_js', $form['#post'][MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] .'_js']);
+  //variable_set(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] .'_text', $form['#post'][MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] .'_text']);
+
+}
+
 /**
  * Formats a form element to use maxlength value and use js.
  *
