View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012271 | mantisbt | feature | public | 2010-08-20 09:38 | 2014-02-02 11:30 |
| Reporter | cfmanrique | Assigned To | |||
| Priority | normal | Severity | feature | Reproducibility | always |
| Status | new | Resolution | open | ||
| Product Version | 1.2.0 | ||||
| Summary | 0012271: 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: 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:
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: he implementado una solución sencilla que trabaja asi:
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! | ||||
| Tags | No tags attached. | ||||
| Attached Files | 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!.
-------------------------------------------------
| ||||