If like me you wish you could add checkbox and radio field types to the custom member profile fields then this is how. There are two files that you will need to modify; mod.member_register.php and mod.member_settings.php. Both are location in the ‘modules > member’ folder.
For this hack to work you will need to add some custom profile fields via the EE control panel. To add a field that will be used as a checkbox use the ‘text’ type and then manually change the field type in the database (exp_member_fields > m_field_type) to ‘checkbox’. For a radio field type use the ‘select’ field type and then manually change the field type in the database to ‘radio’.
One downside of this hack is that once you have manually changed these field values in the database the fields will no longer appear on the ‘edit profile’ screen within the EE control panel. There’s for sure some way to fix this, I just haven’t looked into it yet, if you have time to, report your findings here!
Note: Make sure you backup the original files before going any further!
First off the code to add the new field types to the member registration page open up ‘mod.member_register.php’ and after line number 193 add:
elseif ($row['m_field_type'] == 'checkbox')
{
$field = "<input type=\"checkbox\" name=\"m_field_id_".$row['m_field_id']."\" value=\"y\" class=\"checkbox\" />";
}
elseif ($row['m_field_type'] == 'radio')
{
$items = trim($row['m_field_list_items']);
if ($items != '')
{
$group = "";
foreach (explode("\n", $items) as $v)
{
$v = trim($v);
$field .= "".$v." <input type='radio' name='".'m_field_id_'.$row['m_field_id']."' id='".'m_field_id_'.$row['m_field_id']."' value='".$v."' class='radio'".$checked." /> ";
}
}
}
Now to the code to add the new field types to the members edit profile page. Open ‘mod.member_settings.php’ and after line number 953 add:
elseif ($row['m_field_type'] == 'checkbox')
{
/** ----------------------------------------
/** Render checkbox fields
/** ----------------------------------------*/
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);
}
elseif ($row['m_field_type'] == 'radio')
{
/** ----------------------------------------
/** Render radio fields
/** ----------------------------------------*/
$group = "";
foreach (explode("\n", trim($row['m_field_list_items'])) as $v)
{
$v = trim($v);
$checked = ($field_data == $v) ? " checked='checked'" : '';
$group .= "".$v." <input type='radio' name='".'m_field_id_'.$row['m_field_id']."' id='".'m_field_id_'.$row['m_field_id']."' value='".$v."' class='radio'".$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}', $group, $temp);
}
...and at about line number 1140, inside the ‘update_profile’ function and immediately after the comment ‘/** Update the custom fields’ insert the following:
$checkboxes = array("m_field_id_1");
foreach ($checkboxes as $checkbox_field)
{
if (!isset($_POST[$checkbox_field])) {
$_POST[$checkbox_field] = "n";
}
}
Save your changes and you should be good to go. For further discussion on this topic please see the discussion forum thread which this page was born from.
