It is common to build forms into the theme layer (login, search....) and these forms get blocked altogether. I'm looking for suggestins on how to best handle this. I could, for example, make a token dispatching function that could be called from the theme level.

Comments

robertdouglass’s picture

Proposed solution:

/**
 * ATTENTION THEMERS: use this function if you are hard-coding forms into your theme!
 *
 * Initializes and returns a token. This can be called from the theme level to get a token for a form
 * if your form is hardcoded and doesn't call form_alter when being built the very first time.
 *
 * @param string $form_id
 *   This must match the form_id that will be generated when the form is submitted.
 * @return string
 *   A token. If calling this from your theme, put it in an element like this:
 *
 *   <input type="hidden" name="edit[formsingle_token]" id="edit-formsingle_token" value="< ?php print
 *       formsingle_initialize_token('your_form_id'); ? >" />
 *
 *   This will guarantee that your form doesn't get blocked by the formsingle module.
 */
function formsingle_initialize_token($form_id)  {
  // Make the original token that will later be needed for the form to submit
  $token = md5($form_id. session_id().time());
  $_SESSION['formsingle_tokens'][time()] = $token;
  return $token;
}

This code is now in the current version of the module. Testers needed.

robertdouglass’s picture

Status: Active » Needs review
m3avrck’s picture

Tokens are now in 4.7.4 and 5.0+

So we can use that functionality to fix this.

robertdouglass’s picture

Status: Needs review » Fixed

The #token in core won't work for this. See http://drupal.org/node/107358

Anonymous’s picture

Status: Fixed » Closed (fixed)