View Issue Details

IDProjectCategoryView StatusLast Update
0012271mantisbtfeaturepublic2014-02-02 11:30
Reportercfmanrique Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
Status newResolutionopen 
Product Version1.2.0 
Summary0012271: Enhance for input of email type custom fields.
Description

Many times, our users are not so accurate when writing the email address domain. They mistype the part after the "@". i.e. we got a lot of wrong email addresses such as:
somebody@hotmail (missing ".com")
someone@gemail.com (instead of "gmail")
and so on...

Thus, I've implemented a simple control to minimize this behavior by providing a list of the most commonly used domains, so we can diminish the ammount of wrong email addresses. It works like this:

  1. Add an enumeration of common domains in the "possible values" field of a given email type custom field. (a list of values separated by "|")

  2. For input of email type custom fields, the user is provided with two fields: one for the name part of the email, and a list of the most common domains.

  3. If the domain that is going to be added is not in the list, the user simply writes the whole address in the first part.

  4. The email address is stored in the original custom field, however, for editing the domain part is splitted again so the user gets a consistent functionality.

To achieve this, I only made a few changes to gpc_api.php, and cfdef_standard.php.

See attached preview and code.

Hope it Helps!

Additional Information

En español:

Para evitar que los usuarios ingresen direcciones de email incorrectas como:
somebody@hotmail (le falta ".com")
someone@gemail.com (lo correcto es: "gmail")

he implementado una solución sencilla que trabaja asi:

  1. En el campo "posibles valores" de un campo personalizado, se agrega una lista de los dominios mas usados, separada por "|" como se hace con cualquier enumeración en mantis.}

  2. En pantalla aparecen dos campos para ingresar el correo electrónico: una parte para el nombre y otra con la lista de los dominios mas usados.

  3. Si el dominio que se va a ingresar no está en la lista, el usuario simplemente escribe toda la dirección en el primer espacio.

  4. La direccion de correo se almacena completa en el campo personalizado, pero cuando se edita, el programa divide nuevamente la parte del nombre y la parte del dominio para que el usuario tenga una funcionalidad consistente.

Para lograrlo, solo son necesarios algunos cambios en gpc_api.php y cfdef_standard.php.

Adjunto un ejemplo y los cambios de código necesarios.

Espero que sirva!

TagsNo tags attached.
Attached Files
email_custom_field_input.jpg (79,631 bytes)   
email_custom_field_input.jpg (79,631 bytes)   
custom_field_email_code.txt (4,778 bytes)   
MODIFY CFDEF_STANDARD.PHP
Find this piece of code:
-----------------------------------------------------

$g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_EMAIL ] = array (
	'#display_possible_values' => TRUE,
	'#display_valid_regexp' => TRUE,
	'#display_length_min' => TRUE,
	'#display_length_max' => TRUE,
	'#display_default_value' => TRUE,
	'#function_return_distinct_values' => null,
	'#function_value_to_database' => null,
	'#function_database_to_value' => null,
	'#function_print_input' => 'cfdef_input_textbox',
	'#function_string_value' => 'cfdef_prepare_email_value',
	'#function_string_value_for_email' => 'cfdef_prepare_email_value_for_email',
);

-----------------------------------------------------
and change this line:
-----------------------------------------------------
	'#function_print_input' => 'cfdef_input_textbox',

-----------------------------------------------------
to this:
-----------------------------------------------------	
	'#function_print_input' => 'cfdef_input_email',


-----------------------------------------------------
in the same CFDEF_STANDARD.PHP, add these code at the end:
-----------------------------------------------------

function cfdef_input_email($p_field_def, $t_custom_field_value) {
    # By XFMM
    # Split the value into address and domain
    $t_domains_list = custom_field_prepare_possible_values( $p_field_def['possible_values'] );
    $t_address_part = $t_custom_field_value ;
    $t_domain_part = '' ;
    if( $t_domains_list <> '' ){
        $t_position_at = strpos($t_custom_field_value,'@');
        if( $t_position_at > 0 ){
            $t_address_part = substr($t_custom_field_value,0,$t_position_at);
            $t_domain_part = trim(substr($t_custom_field_value,$t_position_at+1));
        }
    }
    # Let's begin with a single input field.
	echo '<input ', helper_get_tab_index(), ' type="text" name="custom_field_' . $p_field_def['id'] . '" size="40"';
	if( 0 < $p_field_def['length_max'] ) {
		echo ' maxlength="' . $p_field_def['length_max'] . '"';
	} else {
		echo ' maxlength="255"';
	}
	echo ' value="' . $t_address_part .'"';
    echo '></input>';
    # Now, let's add a list with commonly used domains, taken from the "possible values" argument.
    $t_domains_list = custom_field_prepare_possible_values( $p_field_def['possible_values'] );
    if( $t_domains_list <> '' ){
        echo '    @    ';
	    $t_values = explode( '|', $t_domains_list);
	    $t_list_size = 0;	# Treat this as an ENUM, not a list.
	    echo '<select ', helper_get_tab_index(), ' name="custom_field_' . $p_field_def['id'] . '_domain" size="' . $t_list_size . '" style="width: 220px" >';
	    $t_selected_values =  $t_domain_part ;
        $t_selected_value_found = false;
	    # Start with an empty entry.
	    if( $t_domain_part == '' ) {
	        echo '<option value= "" ></option> selected="selected"> ';
	        $t_selected_value_found = true;
         } else {
	        echo '<option value= "" ></option> ';
         }
	    foreach( $t_values as $t_option ) {
            if( $t_option == $t_domain_part ) {
			    echo '<option value="' . $t_option . '" selected="selected"> ' . $t_option . '</option>';
			    $t_selected_value_found = true;
		    }  else {
			   echo '<option value="' . $t_option . '">' . $t_option . '</option>';
		    }
	     } #Foreach
	     # It�s possible to have a value not included in the predefined list.
	     if( !$t_selected_value_found ) {
		     echo '<option value="' . $t_domain_part . '" selected="selected"> ' . $t_domain_part . '</option>';
         }
	     echo '</select>';
     }
}

-----------------------------------------------------
Now, modify GPC_API.PHP 
Find this function:
-----------------------------------------------------

function gpc_get_custom_field( $p_var_name, $p_custom_field_type, $p_default = null ) {

-----------------------------------------------------
And just before the 'default' Statement of the 'switch' structure, add the following:
-----------------------------------------------------
	case CUSTOM_FIELD_TYPE_EMAIL:
             # XFMM: Mix address + domain.
             $t_value = gpc_get_string( $p_var_name, $p_default );
             if( strpos($t_value,'@') == 0 && $t_value<>''){
                 $t_var_name_domain = $p_var_name.'_domain';
                 $t_value .= '@' . gpc_get_string ($t_var_name_domain,'') ;
             }
             return $t_value;
             break;


-------------------------------------------------
Finally, go to manage your custom field, and add some domains in the "possible values" field, to see your solution working!.
-------------------------------------------------
custom_field_email_code.txt (4,778 bytes)   

Activities