I am trying to build an event registration where the primary registrant can register many other attendees on his/her registration.
I want to collect Name, Email, Address, and Phone Number for the primary registrant and only Name and Email for the other attendees that he/she registers.
So far here is what I have done:
/**
* Implements hook_entity_presave
* @param type $entity
* @param type $type
*/
function additional_registrants_entity_presave($entity, $type) {
}
if ($type == 'registration') {
$count = 1;
$field_testing = $entity->field_testing;
foreach ( $field_testing[LANGUAGE_NONE] as $item) {
$count++;
}
$entity->count = $count;
}
}
/*
* Adds a validation hook to the beginning of the #element_validate
* to provide custom validation on the required fields within the
* widget.
*/
function additional_registrants_field_widget_form_alter(&$element, &$form_state, $context) {
switch ($context['instance']['widget']['type']) {
case 'field_collection_embed':
// Check for our specific field.
if ($context['instance']['field_name'] == 'field_testing') {
array_unshift($element['#element_validate'], 'additional_registrants_field_collection_validate');
}
break;
}
}
function additional_registrants_field_collection_validate($element, &$form_state, $form) {
if ($form_state['triggering_element']['#name'] == 'field_testing_add_more') {
// ID and entity_type of the entity (in our case event node).
$entity_id = $form_state['registration']->entity_id;
$entity_type = $form_state['registration']->entity_type;
// Get registration settings for the node
$settings = registration_entity_settings($entity_type, $entity_id);
// Get total capacity
$capacity = $settings['capacity'];
if ($capacity != 0) {
$used_slots = registration_event_count($entity_type, $entity_id);
$extra_registrants_count = 0;
foreach ($form_state['values']['field_testing'][LANGUAGE_NONE] as $item) {
$extra_registrants_count++;
}
// 1 from the registration, add the extra registrants already filled in and one more as we want to add one.
$registration_slots = 1 + $extra_registrants_count;
if ($capacity - $used_slots - $registration_slots < 0) {
$node = node_load($entity_id);
$error_message = t('This event is fully booked. You cannot add another person.');
form_error($form['field_testing'][LANGUAGE_NONE][0]['field_reg_extra_name'], $error_message);
}
}
}
}
Does anyone have any ideas as to how to make this work?
Thanks!
Closed: outdated
1.6
Registration Core
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.