I am building a page which allows our members to select their notification preferences based on a number of options. For example sake, I am giving the option for the member to select notifications when a new message arrives and when an update has occured. They can receive the notification via email, sms, both, or neither.
If I simply build it out as a number of:
HTML code
<tr>
<td>Alert me when a new message comes in:</td>
</tr>
<tr>
<td>
<label><input name="ENREME" type="radio" style="margin-left:30px;" value="EMAIL" <?php if ($smscode == "7" || $smscode == "4") { ?>checked="checked"<?php } ?> tabindex="15" />Email</label>
<label><input name="ENREME" type="radio" style="margin-left:30px;" value="SMS" <?php if ($smscode == "7" || $smscode == "5") { ?>checked="checked"<?php } ?> />SMS</label>
<label><input name="ENREME" type="radio" style="margin-left:30px;" value="BOTH" <?php if ($smscode == "7" || $smscode == "6") { ?>checked="checked"<?php } ?> tabindex="15" />Both</label>
<label><input name="ENREME" type="radio" style="margin-left:30px;" value="NONE" <?php if ($smscode == "0") { ?>checked="checked"<?php } ?> />Don't notify me</label>
</td>
</tr>
<tr>
<td>Alert me when a new update to my site occurs:</td>
</tr>
<tr>
<td>
<label><input name="RECRUITEME" type="radio" style="margin-left:30px;" value="EMAIL" <?php if ($smscode == "7" || $smscode == "1") { ?>checked="checked"<?php } ?> tabindex="15" />Email</label>
<label><input name="RECRUITEME" type="radio" style="margin-left:30px;" value="SMS" <?php if ($smscode == "7" || $smscode == "2") { ?>checked="checked"<?php } ?> /> SMS</label>
<label><input name="RECRUITEME" type="radio" style="margin-left:30px;" value="BOTH" <?php if ($smscode == "7" || $smscode == "3") { ?>checked="checked"<?php } ?> tabindex="15" />Both</label>
<label><input name="RECRUITEME" type="radio" style="margin-left:30px;" value="NONE" <?php if ($smscode == "0") { ?>checked="checked"<?php } ?> />Don't notify me</label>
</td>
</tr>
Variable Encoding and Storage
<?php
if ($_POST['ENREME'] == "BOTH" && $_POST['RECRUITEME'] == "BOTH") {
$notif = 15;
} elseif ($_POST['ENREME'] == "BOTH" && $_POST['RECRUITEME'] == "SMS") {
$notif = 14;
} elseif ($_POST['ENREME'] == "BOTH" && $_POST['RECRUITEME'] == "EMAIL") {
$notif = 13;
} elseif ($_POST['ENREME'] == "BOTH" && $_POST['RECRUITEME'] == "NONE") {
$notif = 12;
} elseif ($_POST['ENREME'] == "EMAIL" && $_POST['RECRUITEME'] == "BOTH") {
$notif = 11;
} elseif ($_POST['ENREME'] == "EMAIL" && $_POST['RECRUITEME'] == "SMS") {
$notif = 10;
} elseif ($_POST['ENREME'] == "EMAIL" && $_POST['RECRUITEME'] == "EMAIL") {
$notif = 9;
} elseif ($_POST['ENREME'] == "EMAIL" && $_POST['RECRUITEME'] == "NONE") {
$notif = 8;
} elseif ($_POST['ENREME'] == "SMS" && $_POST['RECRUITEME'] == "BOTH") {
$notif = 7;
} elseif ($_POST['ENREME'] == "SMS" && $_POST['RECRUITEME'] == "SMS") {
$notif = 6;
} elseif ($_POST['ENREME'] == "SMS" && $_POST['RECRUITEME'] == "EMAIL") {
$notif = 5;
} elseif ($_POST['ENREME'] == "SMS" && $_POST['RECRUITEME'] == "NONE") {
$notif = 4;
} elseif ($_POST['ENREME'] == "NONE" && $_POST['RECRUITEME'] == "BOTH") {
$notif = 3;
} elseif ($_POST['ENREME'] == "NONE" && $_POST['RECRUITEME'] == "SMS") {
$notif = 2;
} elseif ($_POST['ENREME'] == "NONE" && $_POST['RECRUITEME'] == "EMAIL") {
$notif = 1;
} elseif ($_POST['ENREME'] == "NONE" && $_POST['RECRUITEME'] == "NONE") {
$notif = 0;
}
?>
I am left to code for 16 possible variables (and thus creating over 100 lines of code). Can anybody think of a better way to consolidate this code? Based on the selections made, I want the result to equal a single digit (i.e. 28 equals, send email and SMS notifications for both new messages and updates).
Creating a new table or database and making reference calls is not a solution so please do not suggest that.
Thank you!