diff --git a/booking.regn_form.inc b/booking.regn_form.inc index 824d4ab..36e17fc 100644 --- a/booking.regn_form.inc +++ b/booking.regn_form.inc @@ -121,7 +121,11 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all '#maxlength' => 45, '#required' => TRUE, '#default_value' => !empty($data->booking_regn_earlyaccess_code) ? $data->booking_regn_earlyaccess_code : '' - ); + ); + $form['booking_earlyaccess'] = array( + '#type' => 'hidden', + '#value' => 1 + ); } $form['your-details'] = array( @@ -407,27 +411,10 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all //only show the booking agreement tickbox if the node is being created, since this value isn't stored anywhere if ($inserting == TRUE) { - /* - $form['your-details']['booking_regular_cyc'] = array - ( - '#type' => 'checkbox', - '#title' => t('Regularly Attend CYC '), - '#default_value' => empty($data->booking_agreement) ? 0 : $data->booking_agreement, - '#title' => t('I regularly attend CYC events/activities'), - ); */ - $form['your-details']['booking_agreement'] = array( '#type' => 'checkbox', '#title' => t('Aims and Expectations'), '#default_value' => empty($data->booking_agreement) ? 0 : $data->booking_agreement, - /* - '#states' => array( - // Only show this field when the checkbox is unchecked. - 'visible' => array( - ':input[name="booking_agreement"]' => array('checked' => FALSE), - ), - ), - */ '#title' => token_replace(variable_get('booking_registration_aims_rules_checkbox'), booking_define_tokens()), '#description' => token_replace(variable_get('booking_registration_aims_rules_text'), booking_define_tokens()) ); @@ -941,9 +928,21 @@ function booking_form_validate($form, &$form_state) { //watchdog('booking', '
Booking registration form validation:\n@info', array('@info' => print_r( $data, true))); //if necessary, validate early access code - if (variable_get('booking_enable_earlyaccess_codes', 0) == 1) { + if (variable_get('booking_enable_earlyaccess_codes', 0) == 1 && (isset($data['booking_earlyaccess']) && $data['booking_earlyaccess'] == 1)) { if (isset($data['booking_regn_earlyaccess_code']) && $data['booking_regn_earlyaccess_code'] != '') { - + //perform a database lookup against the booking_regn_earlyaccess_codes table + $code_check = db_query("SELECT cid " . + "FROM {booking_regn_earlyaccess_codes} " . + "WHERE booking_regn_earlyaccess_code = :code AND booking_eventid = :eid AND booking_regn_earlyaccess_code_avail = 'Y'", + array( + ':code' => $data['booking_regn_earlyaccess_code'], + ':eid' => $event->eid, + ) + )->fetchObject(); + //see if we got a result + if (! $code_check) { + form_set_error('booking_regn_earlyaccess_code', t('You have entered an invalid early registration code. If you do not have a code, please wait until normal registrations open.')); + } } else { form_set_error('booking_regn_earlyaccess_code', t('You must enter an early access code to register now. If you do not have a code, please wait until normal registrations open.'));