test ajax validation of early access code
This commit is contained in:
@@ -111,6 +111,9 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Early Registration Code'
|
||||
);
|
||||
$form['early-access']['booking_earlyaccess_feedback_wrapper'] = array(
|
||||
'#markup' => '<div id="booking-earlyaccess-feedback-wrapper"></div>',
|
||||
);
|
||||
$form['early-access']['booking_earlyaccess_explanation'] = array(
|
||||
'#type' => 'container',
|
||||
'#children' => t("<p>If you have been given an early-access code for registration, please enter it below. " .
|
||||
@@ -122,7 +125,12 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
|
||||
'#title' => t('Unique Early-Access Code'),
|
||||
'#maxlength' => 45,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_earlyaccess_code) ? $data->booking_earlyaccess_code : ''
|
||||
'#default_value' => !empty($data->booking_earlyaccess_code) ? $data->booking_earlyaccess_code : '',
|
||||
'#ajax' => array(
|
||||
'event' => 'change',
|
||||
'wrapper' => 'booking_earlyaccess_feedback_wrapper',
|
||||
'callback' => 'booking_earlyaccess_feedback_callback',
|
||||
),
|
||||
);
|
||||
$form['booking_earlyaccess'] = array(
|
||||
'#type' => 'hidden',
|
||||
@@ -930,7 +938,36 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
|
||||
return $form;
|
||||
}
|
||||
|
||||
// @todo - validate the early access code here, booking_earlyaccess_code
|
||||
function booking_earlyaccess_feedback_callback($form, &$form_state) {
|
||||
global $event;
|
||||
$node = $form_state['values']['form_id'];
|
||||
$data = $form_state['input'];
|
||||
|
||||
//if necessary, validate early access code
|
||||
if (variable_get('booking_enable_earlyaccess_codes', 0) == 1 && (isset($data['booking_earlyaccess']) && $data['booking_earlyaccess'] == 1)) {
|
||||
if (isset($data['booking_earlyaccess_code']) && $data['booking_earlyaccess_code'] != '') {
|
||||
//perform a database lookup against the booking_earlyaccess_codes table
|
||||
$code_check = db_query("SELECT cid " .
|
||||
"FROM {booking_earlyaccess_codes} " .
|
||||
"WHERE booking_earlyaccess_code = :code AND booking_eventid = :eid AND booking_earlyaccess_code_avail = 'Y'",
|
||||
array(
|
||||
':code' => $data['booking_earlyaccess_code'],
|
||||
':eid' => $event->eid,
|
||||
)
|
||||
)->fetchObject();
|
||||
//see if we got a result
|
||||
if (! $code_check) {
|
||||
return '<div id="booking-earlyaccess-feedback-wrapper"><span color="#8c2e0b">You have entered an invalid early registration code. If you do not have a code, please wait until normal registrations open.</span></div>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
return '<div id="booking-earlyaccess-feedback-wrapper"><span color="#8c2e0b">You must enter an early access code to register now. If you do not have a code, please wait until normal registrations open.</span></div>';
|
||||
}
|
||||
}
|
||||
|
||||
#fallback
|
||||
return '<div id="booking-earlyaccess-feedback-wrapper"></div>';
|
||||
}
|
||||
|
||||
function booking_form_validate($form, &$form_state) {
|
||||
global $event;
|
||||
|
@@ -139,11 +139,11 @@ function booking_room_edit_form($node, &$form_state, $nid) {
|
||||
'#title' => t('Room Location'),
|
||||
'#options' => $location_options,
|
||||
'#default_value' => $person->booking_room_location_id,
|
||||
'#ajax' => array(
|
||||
'event' => 'change',
|
||||
'wrapper' => 'booking_roomnum_wrapper',
|
||||
'callback' => 'booking_roomnum_ajax_callback',
|
||||
),
|
||||
'#ajax' => array(
|
||||
'event' => 'change',
|
||||
'wrapper' => 'booking_roomnum_wrapper',
|
||||
'callback' => 'booking_roomnum_ajax_callback',
|
||||
),
|
||||
);
|
||||
|
||||
$form['booking_room_number'] = array(
|
||||
@@ -154,18 +154,18 @@ function booking_room_edit_form($node, &$form_state, $nid) {
|
||||
'#suffix' => '</div>',
|
||||
'#options' => _booking_get_roomedit_roomnum_options($selected_room_location),
|
||||
'#default_value' => isset($form_state['values']['booking_room_number']) ? $form_state['values']['booking_room_number'] : $person->booking_room_number,
|
||||
'#ajax' => array(
|
||||
'event' => 'change',
|
||||
'wrapper' => 'booking_bedtype_wrapper',
|
||||
'callback' => 'booking_bedtype_ajax_callback',
|
||||
),
|
||||
'#ajax' => array(
|
||||
'event' => 'change',
|
||||
'wrapper' => 'booking_bedtype_wrapper',
|
||||
'callback' => 'booking_bedtype_ajax_callback',
|
||||
),
|
||||
);
|
||||
|
||||
$form['booking_room_bedtype'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Bed Type'),
|
||||
'#prefix' => '<div id="booking_bedtype_wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
'#prefix' => '<div id="booking_bedtype_wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
'#options' => _booking_get_roomedit_bedtype_options($selected_room_location, $selected_room_num),
|
||||
'#default_value' => $person->booking_room_bedtype,
|
||||
);
|
||||
|
Reference in New Issue
Block a user