Can I use drupal_get_form and drupal_render within a custom Drupal 7 input filter? As the title says:  I've got a custom input filter in Drupal 7 which replaces a token with a custom drupal form. Without showing the complete code, which might just confuse things, The main essence is the following:

function _my_filter($text, $filter = NULL, $format = NULL, $langcode = NULL, $cache = NULL, $cache_id = NULL) {
  $rendered_text = $text;
  preg_match_all(MY_CUSTOM_REGEX, $text, $matches);
  if (!empty($matches[0])) {
    foreach ($matches[0] as $match) {
      $custom_form = drupal_get_form('my_custom_form'); 
      $replacement = drupal_render($custom_form);
      $rendered_text = str_replace($match, $replacement, $rendered_text);        
    }
  }
  return $rendered_text;
}


For some reason when the node is being saved this times out.  I've narrowed it down to being something in my drupal_get_form (but this form renders fine without any problems outside of an input filter).  

Can I use drupal_get_form and drupal_render within an input filter like this?
I believe you can do this, but not by default. You'll need to disable caching. This is because the filtered data is cached, so your form will only work the first time. To disable caching, you need to set cache to FALSE in your hook_filter_info() definition.

If it's timing out, then it may be a problem in your form definition itself - does the for work in non-filter context (ie embedded directly into a page)?