Use the 'form_build_id' to prevent duplicate submissions. This is located at
$form_state['input']['form_build_id']
(drupal-7) and is generated with each form load.
See created module: http://drupal.org/sandbox/interlated/1963144.
A database table or widget field would be required to store it with each submission. Ideally the table holding the field would be locked. In a validation callback or node_save hook. A specific field per content type to prevent too much locking. The validation messages drupal_set_message() saying that multiple submissions were detected would still display. In practice the locking may become too cumbersome, so a cron job is required to clean it up.
There is a fair bit of code required. Create a module, then register field, widget, formatter. Create a widget form with a validator, write the validator. Finally write a cron job to delete duplicate nodes, or at least delete duplicate tallied points. Add the created field to your node.
Firstly, set up a constant.
ognotify.info
files[] = includes/OgNotifyManage.inc
In the declared file:
class OgNotifyManage {
const field_id = 'duplicate_token';
}
In the .module file:
/**
* Define the field definition for the node editing form.
*/
function ognotify_field_info() {
return array(
OgNotifyManage::field_id => array(
'label' => t('Token'),
'description' => t('Record tokens to reduce duplicates.'),
'default_widget' => OgNotifyManage::field_id,
'default_formatter' => OgNotifyManage::field_id,
),
);
}
/**
* Define the field for sending invitations.
*/
function ognotify_field_widget_info() {
return array(
OgNotifyManage::field_id => array(
'label' => t('Detect Duplicates'),
'field types' => array(OgNotifyManage::field_id),
),
);
}
/**
* Implements hook_field_formatter_info().
*/
function ognotify_field_formatter_info() {
return array(
OgNotifyManage::field_id => array(
'label' => t('Default'),
'field types' => array('duplicate_token'),
),
);
}
/**
* Define whether the field is empty. This is required by field API and
* determines whether the field is to be saved.
*/
function ognotify_field_is_empty($item, $field) {
// items. No applicable concept of empty.
if (empty($item[OgNotifyManage::field_id])) {
return TRUE;
}
return FALSE;
}
function ognotify_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$element[OgNotifyManage::field_id] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#theme' => 'ognotify_form',
'#weight' => 10,
'#element_validate' => array('ognotify_duplicates_validate'),
);
return $element;
}
function ognotify_duplicates_validate($element, &$form_state) {
// Finally do some entity queries for our form token
// We can do a rough first check for duplicates here, but cannot guarantee
// that another node has been saved while we are checking without locking the
// field table.
// Save the form token in the form.
form_set_value($element, $form_state['input']['form_token'] , $form_state);
}
function ognotify_cron() {
// Do queries for nodes with duplicate form tokens.
}
It looks like a standard module. Let me know if you agree and I could help create it.
I was surprised that drupal doesn't just do this. The token answer is a good one.