First thanks for the module. I love the ingenuity of it! I was needed to use it to protect my comment forms and some webforms i had made. So i checked the protect all forms. But then i noticed that is was stopping the search form from being input. So i needed a way to remove the search form and only select the forms that i wanted. SO i dug into the code and laughed when i saw this:

/**
 * Build an array of all the protected forms on the site, by form_id.
 *
 * Currently only works for user_register_form. Pfft!
 *
 * @todo - Build query dynamically, using db_select...
 */

So after some tinkering, i came up with this. I know its not the easiest way, but it works for me. In the honeypot.admin.inc file on line 51 there is a checkbox to enable protection for the user registration form. I copied and pasted this a couple times for each type of form i wanted to protect. To set the variable name i went and got the form id from each form i wanted to protect. Then i added "honeypot_form_" to the beginning of it (***this is important***).

$form['enabled_forms']['honeypot_form_search_block_form'] = array(
      '#type' => 'checkbox',
      '#title' => t('Search Form'),
      '#default_value' => variable_get('honeypot_form_search_block_form', 0),
    );
	$form['enabled_forms']['honeypot_form_comment_node_article_form'] = array(
      '#type' => 'checkbox',
      '#title' => t('Article Comment Forms'),
      '#default_value' => variable_get('honeypot_form_comment_node_article_form', 0),
    );

This gives me checkboxes and sets variables for each form ID i needed.

On to honeypot.module...

Then i needed to make the form show up when these forms are rendered. So in order to get the form ID that i wanted, i needed to query the variable table and pull out any variables that started with "honeypot_form_". After i got the list of variables i needed to see if they were set, and if so return the form ID. After iterating through the list of forms, i needed to return an array of form IDs. (Im sure there is a better way to do it, but im not exactly a professional coder.)

function honeypot_get_protected_forms() {
	$forms = array();
	$result = db_select('variable', 'v')
    ->fields('v')
    ->condition('name', db_like('honeypot_form') . '%', 'LIKE')
    ->execute()
    ->fetchCol();
	
  foreach($result as $record){
	  if(variable_get($record) == 1){
		  $needle = 'honeypot_form_';
		  $form_id = str_replace($needle, '',$record);
		  array_push($forms, $form_id);
	  }
  }
  return $forms;
}

I have attached a patch for the module file. I figured since everyone is gong to want to protect different forms, they can just copy the snippet above and replace what they need to.

Like i said, i am NOT a coder, and there is probably better, more drupalish ways of doing this, but this works for me.

Have fun, and again, thanks for the module.

Comments

geerlingguy’s picture

Yeah, I really should expand on my code comments there, shouldn't I? :-)

I'm glad you got things working for your site. I will be adding more forms (and types of forms) as soon as I get a little time (might do it on a flight to Boston this week). I want to make it extensible so anyone and everyone can enable the module for any forms they want, but that takes a little time :-)

As a start, I will probably add in node forms, some other standard drupal forms, and comment forms. Sooner or later I'll also add in any webforms (if that module's enabled).

[Edit: Also, if you download the -dev release, the search form issue (and login form issues) should be resolved.]

anarcat’s picture

Comment forms would be a must for me. :)

geerlingguy’s picture

Assigned: Unassigned » geerlingguy
Priority: Normal » Major

I'll pop this up to major, because right now, the module's kind of all-or-nothing (like a shotgun approach to form protection). I'd like to start with comment forms, then add in node forms, webforms, and others.

geerlingguy’s picture

Status: Active » Patch (to be ported)
FileSize
3.78 KB

I've worked this up in a more performant way, using a static cache and database cache fallback, and I've built the forms list in a bit more of a future-proof style. See attached patch for 7.x (I'll work on a backport in a bit... hopefully! I'm watching the World Series right now...).

geerlingguy’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

Committed to 7.x (see: http://drupalcode.org/project/honeypot.git/commit/ce9075b). Moving this issue to 6.x for straight backport. Caching logic and a few other bits will need to be changed, though.

geerlingguy’s picture

Status: Patch (to be ported) » Fixed
FileSize
3.8 KB

Attached patch was committed to the 6.x branch (see: http://drupalcode.org/project/honeypot.git/commit/8cf3511). Please let me know if you have any problems with this fix!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.