From 8cce7121a33256d73f5ffbf3bda63ceb0875ca97 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Sat, 4 Jun 2016 12:56:00 +1000 Subject: [PATCH] hide special requirements fieldset if not needed --- booking.travel.inc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/booking.travel.inc b/booking.travel.inc index f965905..866519f 100644 --- a/booking.travel.inc +++ b/booking.travel.inc @@ -290,12 +290,22 @@ function travel_form($node, &$form_state, $inserting = FALSE, $node = NULL, $tok ), ); */ - $form['requirements'] = array( - '#type' => 'fieldset', - '#title' => 'Special Requirements' - ); + + //calculate which fields to show and whether we need to show the fieldset at all + $show_dietary = variable_get('booking_enable_dietary', 0) == 1 || $inserting == FALSE; + $show_medical = variable_get('booking_enable_medcond', 0) == 1 || $inserting == FALSE; + $show_roommate = variable_get('booking_enable_roommate', 0) == 1 || $inserting == FALSE; + $show_bf_gf = $person->booking_partner_id == 0 || $inserting == FALSE; + $show_special_requirements = ($show_dietary || $show_medical || $show_roommate || $show_bf_gf); + + if ($show_special_requirements) { + $form['requirements'] = array( + '#type' => 'fieldset', + '#title' => 'Special Requirements' + ); + } //only show the dietary field if we're allowed to - if (variable_get('booking_enable_dietary', 0) == 1 || $inserting == FALSE) { + if ($show_dietary) { $form['requirements']['booking_dietary'] = array( '#type' => 'textfield', '#title' => t('Special dietary requirements?'), @@ -304,7 +314,7 @@ function travel_form($node, &$form_state, $inserting = FALSE, $node = NULL, $tok ); } //display the medical conditions question if it is enabled - if (variable_get('booking_enable_medcond', 0) == 1 || $inserting == FALSE) { + if ($show_medical) { $form['requirements']['booking_medical_conditions'] = array( '#type' => 'textfield', '#title' => t('Please describe any medical condition we need to know about.'), @@ -315,7 +325,7 @@ function travel_form($node, &$form_state, $inserting = FALSE, $node = NULL, $tok ); } //only show the room mate field if we're allowed to - if (variable_get('booking_enable_roommate', 0) == 1 || $inserting == FALSE) { + if ($show_roommate) { //married people won't need to select a room mate if ($person->booking_partner_id == 0) { $form['requirements']['booking_room_mate1'] = array( @@ -329,7 +339,7 @@ function travel_form($node, &$form_state, $inserting = FALSE, $node = NULL, $tok } } //only show this field if this person isn't married - if ($person->booking_partner_id == 0 || $inserting == FALSE) { + if ($show_bf_gf) { $form['requirements']['booking_bf_gf_nid'] = array( '#type' => 'textfield', '#title' => t('Registration ID of Boyfriend/Girlfriend to be placed in the same discussion groups as you.'),