I am wondering, if the defined elements in the admin-settings under 'Text fields to analyze' are ignored, if they are already mapped with a mollom-key.

For example the contact-module:
File: mollom.module

function contact_mollom_form_info($form_id) {
  switch ($form_id) {
    case 'contact_site_form':
      $form_info = array(
        'mode' => MOLLOM_MODE_ANALYSIS,
        'bypass access' => array('administer contact forms'),
        'mail ids' => array('contact_page_mail'),
        'elements' => array(
          'subject' => t('Subject'),
          'message' => t('Message'),
        ),
        'mapping' => array(
          'post_title' => 'subject',
          'author_name' => 'name',
          'author_mail' => 'mail',
        ),
      );
      return $form_info;

Here is a 'subject' in the 'elements' array defined. The 'subject' is mapped to 'post_title'.
When i have a look into the 'mollom_validate_analysis'-function in the 'mollom.module' file, i find the following line:

 // Perform textual analysis.
  $all_data = mollom_form_get_values($form_state, $form_state['mollom']['enabled_fields'], $form_state['mollom']['mapping']);

$form_state['mollom']['enabled_fields'] contains the elements, which are checked in the administration UI.
$form_state['mollom']['mapping'] contains the following (as described in the info-hook):

array
  'post_title' => string 'subject' (length=7)
  'author_name' => string 'name' (length=4)
  'author_mail' => string 'mail' (length=4)

And the result of this line ($all_data) is the following:

array
  'post_title' => string 'test-subject' (length=12)
  'post_body' => string 'test-message' (length=12)
  'author_name' => string 'test-name' (length=9)
  'author_mail' => string 'test@example.com' (length=16)
  'author_ip' => string '127.0.0.1' (length=9)

It seems, that the "subject" is always taken in the mapping, regardless it is checked in the administration UI or not. Is that a bug / should it be removed from the elements-array in the info-hook?

Comments

sun’s picture

If I understand this correctly, then you're saying that the value of "Subject" is taken over for post_title, even though "Subject" is not enabled in the configuration for the protected form?

Moloc’s picture

Yes, thats exactly what i tried to say.

I just found the following information in the function description of mollom_form_get_values():

/* [...]
 * - All fields specified in 'mapping', for which there is a submitted value,
 *   but which were NOT selected for textual analysis, are assigned to the
 *   specified data property. This is usually the case for form elements that
 *   hold system user information.
 *[...] */

Does the description "NOT selected for textual analysis" also mean, that if there is a field defined in the info-hook elements-array, we are able to configure it in the protected form, but we don't care it's state? Then it is a bit confusing. Better hide all "mapped"-elements in the configuration of the protected form or enable them by default and protect them from editing.

Or is it a feature: As at least one element in text-analysis has to be enabled - so we enable subject (which is mapped to post_title) and disable message (therefore we do not have a post_body). (Regardless, if it makes sense or not.)

sun’s picture

Issue tags: +API change