Przeglądaj źródła

Converted date fields to dropdowns.

Alan Lam 8 lat temu
rodzic
commit
02c0f0e689

+ 1 - 1
controllers/register.php

@@ -29,7 +29,7 @@ try {
 		$user->first_name = http::value("first_name", "trim");
 		$user->last_name = http::value("last_name", "trim");
 		$user->gender = http::value("gender", "trim");
-		$user->date_of_birth = http::value("date_of_birth", "trim");
+		$user->date_of_birth = http::getDateFromFields("date_of_birth");
 		$user->phone = http::value("phone", "trim");
 		$user->dts_registered = gmdate("Y-m-d H:i:s");
 

+ 1 - 1
controllers/user_edit.php

@@ -31,7 +31,7 @@ if($submit) {
 		$user->title = http::value("title", "trim");
 		$user->first_name = http::value("first_name", "trim");
 		$user->last_name = http::value("last_name", "trim");
-		$user->date_of_birth = http::value("date_of_birth", "trim");
+		$user->date_of_birth = http::getDateFromFields("date_of_birth");
 		$user->phone = http::value("phone", "trim");
 		$user->gender = http::value("gender", "trim");
 

+ 13 - 0
engine/form.php

@@ -35,6 +35,19 @@ class Form {
 		}
 	}
 
+	public static function renderYearOptionsDescending($min = null, $max = null, $selected_value = null) {
+
+		if(empty($min)) $min = date("Y") - 100;
+		if(empty($max)) $max = date("Y") - 16;
+
+		for($i = $max; $i >= $min; $i--) {
+			$selected = ($selected_value == $i) ? "selected" : "";
+			?>
+			<option value="<?=$i?>" <?=$selected?>><?=$i?></option>
+			<?php
+		}
+	}
+
 	public static function renderMonthOptions($selected_value = null) {
 		for($i = 1; $i <= 12; $i++) {
 			$selected = ($selected_value == $i) ? "selected" : "";

+ 18 - 1
views/register.php

@@ -86,7 +86,24 @@
 				<div class="row mb-1">
 					<label class="col-sm-4 col-form-label"  for="date-of-birth">Date of Birth</label>
 					<div class="col-sm">
-						<input class="form-control" type="date" name="date_of_birth" id="date-of-birth" placeholder="YYYY-MM-DD" value="<?=htmlspecialchars($user->date_of_birth)?>" required />
+						<select class="form-control w-auto d-inline-block" name="date_of_birth_day" id="date-of-birth-day">
+							<option value="">Day</option>
+							<?php
+							Form::renderDayOptions();
+							?>
+						</select>
+						<select class="form-control w-auto d-inline-block" name="date_of_birth_month" id="date-of-birth-month">
+							<option value="">Month</option>
+							<?php
+							Form::renderMonthOptions();
+							?>
+						</select>
+						<select class="form-control w-auto d-inline-block" name="date_of_birth_year" id="date-of-birth-year">
+							<option value="">Year</option>
+							<?php
+							Form::renderYearOptionsDescending();
+							?>
+						</select>
 					</div>
 				</div>
 				<div class="row mb-1">

+ 23 - 1
views/user_edit_form.php

@@ -1,3 +1,8 @@
+<?php
+
+$date_of_birth_parts = explode("-", $user->date_of_birth);
+
+?>
 <script>
 var userId = <?=$user->id?>;
 </script>
@@ -85,7 +90,24 @@ var userId = <?=$user->id?>;
 				<div class="row mb-1">
 					<label class="col-sm-4 col-form-label"  for="date-of-birth">Date of Birth</label>
 					<div class="col-sm">
-						<input class="form-control" type="date" name="date_of_birth" id="date-of-birth" placeholder="YYYY-MM-DD" value="<?=htmlspecialchars($user->date_of_birth)?>" required />
+						<select class="form-control w-auto d-inline-block" name="date_of_birth_day" id="date-of-birth-day">
+							<option value="">Day</option>
+							<?php
+							Form::renderDayOptions($date_of_birth_parts[2]);
+							?>
+						</select>
+						<select class="form-control w-auto d-inline-block" name="date_of_birth_month" id="date-of-birth-month">
+							<option value="">Month</option>
+							<?php
+							Form::renderMonthOptions($date_of_birth_parts[1]);
+							?>
+						</select>
+						<select class="form-control w-auto d-inline-block" name="date_of_birth_year" id="date-of-birth-year">
+							<option value="">Year</option>
+							<?php
+							Form::renderYearOptionsDescending(null, null, $date_of_birth_parts[0]);
+							?>
+						</select>
 					</div>
 				</div>
 			</div>