Welcome to Elgg's documentation
This is the place to find documentation on all aspects of Elgg. If you would like to contribute your own documentation please do; we want this to be a real community effort!
Profile Field Types: radio buttons, dates, drop down lists
From Elgg Documentation
Editing Profile Field Types: radio buttons, dates, drop down lists, i.e. adding and changing Field Types, i.e. $ftype, case, field_type.
1. Field Types ("field_type") used in profile.config.php (/mod/profile/profile.config.php) determine the type of field. The field_type "radio" is for buttons, "select" is for a drop down menu, and "date_select" would be used to add a date. There are others and you can create your own.
2. The primary field cases are set in /lib/displaylib.php beginning with “case "text":” at around line 140.
3. The cases set in /blog/lib/lib.php begin at around line 485 with “case "vertical_radio":”
4. The cases set in /blog/lib/lib.php are newer and were intended for the blog mod and not the profile mod. Prior to using any of them some updates to other files need to be made as follows:
5. Edit profile/profile.class.php' file. Look at about line 222 for:
$frequired = $field->required;
}
Add the following on the lines after the }
// begin add radio and select case functionality
if($ftype == "radio" || $ftype == "select" ){ // Add here the types that you want to support
$foptions = $field->options;
}
else{
$foptions = "";
}
// end add radio and select case functionality
6. In the example above we have added the cases “radio” and “select.” You could add others. Some may work without adding them here. I used case "date_select" successfully without adding it here.
7. Next we would go to around line 277 and find:
$column1 = display_input_field(array("profiledetails[" . $fname . "]",$value->value,$ftype,$fname,@$value->ident,$page_owner));
and replace with:
// $column1 = display_input_field(array("profiledetails[" . $fname . "]",$value->value,$ftype,$fname,@$value->ident,$page_owner));
$column1 = display_input_field(array("profiledetails[" . $fname . "]",$value->value,$ftype,$fname,@$value->ident,$page_owner,$foptions,$flines));
8. In /lib/displaylib.php at around line 369 look for:
case "text":
case "mediumtext":
case "longtext":
$run_result = nl2br(stripslashes($parameter[0]));
break;
and replace it with this
case "text":
case "mediumtext":
case "longtext":
case "radio":
case "date_select":
case "select":
$run_result = nl2br(stripslashes($parameter[0]));
break;
9. You could add in any other cases you plan to use as well.
10. Now n your 'mod/profile/profile.config.php' you can now use three new cases which are the most likely ones you will want to use. Here are three examples of how to use them:
$data['profile:details'][] = (object)(array(
"name" => __gettext("Gender"),
"internal_name" => "gender",
"field_type" => "radio",
"options" => array('male'=>__gettext('Male'),'female'=>__gettext('Female')),
"description" => __gettext("Please select male or female."),
"user_type" => "person",
"category" => __gettext("Basic Details "),
"col1" => true,
"invisible" => false,
"required" => true,
"user_type" => "person",
));
$data['profile:details'][] = (object)(array(
"name" => __gettext("Birthdate"),
"internal_name" => "dob",
"field_type" => "date_select",
"description" => __gettext("So we can send you a birthday card"),
"user_type" => "person",
"category" => __gettext("Basic Details "),
"col1" => true,
"invisible" => false,
"required" => true,
));
$data['profile:details'][] = (object)(array(
"name" => __gettext("Marital Status”),
"internal_name" => "status",
"field_type" => "select",
"options" => array('single'=>__gettext('Single'),'unavailable'=>__gettext('In a Relationship'), 'married'=>__gettext('Married')),
"description" => __gettext("Your Relationship Status."),
"user_type" => "person",
"category" => __gettext("Basic Details"),
"col1" => true,
"invisible" => false,</nowiki>
"required" => true,
));
11. You may change the date_select case a little as follows if you like. In /blog/lib/lib.php look around line 535 for: </script>"; and if you prefer to have the month before the date ala American style and capitalize the dd, mm, and yy then simply change this:
for($i=0;$i<31;$i++){
$data['dd'][] = ($i+1);
}
for($i=0;$i<12;$i++){
$data['mm'][] = ($i+1);
}
$ya = getdate();
for($i=0;$i<100;$i++){
$data['yyyy'][] = (($ya['year']-99)+$i);
To this:
// for($i=0;$i<31;$i++){
// $data['dd'][] = ($i+1);
for($i=0;$i<12;$i++){
$data['MM'][] = ($i+1);
}
for($i=0;$i<31;$i++){
$data['DD'][] = ($i+1);
// for($i=0;$i<12;$i++){
// $data['mm'][] = ($i+1);
}
for($i=0;$i<100;$i++){
$data['YYYY'][] = (($ya['year']-99)+$i);
12. If you need any of this to be translated into other languages then you will need to add all the new gettexts to the English file and to all the other languages you use as well. That is explained elsewhere.

