Download & Extend

Forms built into the theme are blocked

Project:Form single
Version:4.7.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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

#1

Proposed solution:

<?php
/**
* 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.

#2

Status:active» needs review

#3

Tokens are now in 4.7.4 and 5.0+

So we can use that functionality to fix this.

#4

Status:needs review» fixed

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

#5

Status:fixed» closed (fixed)
nobody click here