Okay, I'm building a module that takes a db table full of bad words (single words and phrases) and uses those words whenever anone but the site admin submits a form. If a bad word is found in the submission form, I have to redirect the user back to the form, post an error message saying that the form couldn't be submitted due to a bad word (I can't let them know what the bad word is either) and have them try again.

Now, I'm not looking for comments on whether or not this is a good idea, I just have to do what my client needs me to do. I do have a few ideas, but I've hit a few walls during my initial development. I like using a hook_nodeapi('submit') due to the access on I have on the $node being passed in. My problem is that $node is a structured array and I don't want to add overhead checking stuff thats not being created by the user. I could just go through the structure and concatenate everything, then check and see if my blacklisted words exist, but thats amazingly slow. What I'm looking for is a way to just get the submitted data.

I've messed with the hook_filter and I don't like the fact that I don't have access to all of the fields. Theres got to be a way to get just the data I need so I can try to achieve decent preformance on form submissions.

If any of you have any ideas on how to get that set of data efficiently, or if you can think of a better way to approach such a module, please let me know. Also, I have looked at the wordfilter module and its not what I'm looking for. Plus it seems like they don't even check every form item.

Thanks everyone,
Tyler Wright

Comments

twright’s picture

I just got back to work today (I posted this on Friday) and I saw how quickly this got buried. If any of you have any ideas, please feel free to pass them along.

Thanks
Tyler Wright

jenlampton’s picture

you can use the hook_form_alter to add a validation function to the form, then have your custom validation function test for bad words:

function custom_module_form_alter($form_id, &$form){
// test for the form_id you are trying to catch
  // add the validation function 
  $form['#validate']['custom_module_form_validate] = array();
}

function custom_module_form_validate($form_values, $form_id){
// validate that there are no swear-words in the $form_values
// return your result
}
kenorb’s picture