Ok, I’ve hacked mod.member_settings.php to display checkbox type fields on the edit profile page. Here’s what I’ve done.
I’ve attached my copy of mod.member_settings.php for ease but for the record the additional code I have added is as follows. In the ‘edit_profile’ fucntion beneath the code snippet that renders pull down menus:
elseif ($row['m_field_type'] == 'checkbox')
{
/** ----------------------------------------
/** Render checkbox fields
/** ----------------------------------------*/
// Is checked?
if ($REGX->form_prep($field_data) == "y") {
$field_checked = " checked='checked'";
} else {
$field_checked = "";
}
$input = "<input type='checkbox' name='".'m_field_id_'.$row['m_field_id']."' id='".'m_field_id_'.$row['m_field_id']."' value='y' class='checkbox'".$field_checked." />";
$temp = str_replace('{lang:profile_field}', $required.$row['m_field_label'], $temp);
$temp = str_replace('{lang:profile_field_description}', $row['m_field_description'], $temp);
$temp = str_replace('{form:custom_profile_field}', $input, $temp);
}
And in the update_profile function immediately beneath the ‘Update the custom fields’ comment:
// Check for checkboxes without values
// Populate this array with the field name which are of checkbox type
$checkboxes = array("m_field_id_1");
foreach ($checkboxes as $checkbox_field)
{
if (!isset($_POST[$checkbox_field])) {
$_POST[$checkbox_field] = "n";
}
}
Note that you will need to edit the ‘checkboxes’ array in snippet above to include the field names which you have added that are of the checkbox type. You will also need to manually change the m_field_type value for each field to ‘checkbox’ for this hack to work. I guess this could be improved by dynamically generating the array from the database, doing a select of all fields with a type of ‘checkbox’. If anyone wants to pitch in with that, feel welcome! 😊
Let me know if you can see anywhere else that this can be improved. I’m no PHP guru by any stretch of the imagination! Now onto getting radio buttons to work… 😉
Mod Edit: Attachment removed. Please review our license about distributing core files.