Results 1 to 5 of 5

Thread: indicates for improper information in special field

  1. #1
    goodharry is offline Member
    Join Date
    Apr 2007
    Posts
    7

    Default indicates for improper information in special field

    Hello everyone,

    I notice that some times the "indicates" comes out when the form is filled in a imprroper way. And i want to modify the field (may be add a custom one if it doesn't work well) and let the sugar gives an indicate warning if the input information in this field is already in the database (information should be unique) . which part of the source code should i modify?

    Thanks in advance.

  2. #2
    pblag's Avatar
    pblag is offline Sugar Community Member
    Join Date
    Jul 2006
    Location
    Ukraine (Chernivtsy)
    Posts
    347

    Default Re: indicates for improper information in special field

    Hi!

    As i understand you are talking about "Check form data" functionality. Unfortunately it is Java Script functionality and you can't load data from database to validate your custom field.

    However you can use validating functionality that exists in module Contacts file ContactFormBase.php

    there is functionality for checking "first name + last name"
    if item already exists than you'll be redirected to new page with question like " do you want to create new record with existing data?"



    if(!empty($focus->portal_name)) {
    $query = "SELECT portal_name from contacts where portal_name = '{$focus->portal_name}' AND deleted=0 ";
    if(!empty($focus->id)) $query .= " AND id <> '$focus->id'";
    $result = $GLOBALS['db']->query($query, true, "Error selecting possible duplicate users: ");
    $dup_users = $GLOBALS['db']->fetchByAssoc($result);

    if (!empty($dup_users)) {
    header("Location: index.php?action=Error&module=Users&error_string=" .urlencode($mod_strings['LBL_PORTAL_DUPLICATE_USER_NAME']));
    sugar_die();
    }

    }


    you can use this code in your module where you are going to add new custom fields.

    BTW: you have to understand PHP and SQL for doing this.
    Petro Blagodir
    petro@blagodir.ua
    http://www.blagodir.com
    Blagodir Ltd.( SugarCRM - Consultations, Development and Support)

  3. #3
    goodharry is offline Member
    Join Date
    Apr 2007
    Posts
    7

    Default Re: indicates for improper information in special field

    Quote Originally Posted by pblag
    Hi!

    As i understand you are talking about "Check form data" functionality. Unfortunately it is Java Script functionality and you can't load data from database to validate your custom field.

    However you can use validating functionality that exists in module Contacts file ContactFormBase.php

    there is functionality for checking "first name + last name"
    if item already exists than you'll be redirected to new page with question like " do you want to create new record with existing data?"



    if(!empty($focus->portal_name)) {
    $query = "SELECT portal_name from contacts where portal_name = '{$focus->portal_name}' AND deleted=0 ";
    if(!empty($focus->id)) $query .= " AND id <> '$focus->id'";
    $result = $GLOBALS['db']->query($query, true, "Error selecting possible duplicate users: ");
    $dup_users = $GLOBALS['db']->fetchByAssoc($result);

    if (!empty($dup_users)) {
    header("Location: index.php?action=Error&module=Users&error_string=" .urlencode($mod_strings['LBL_PORTAL_DUPLICATE_USER_NAME']));
    sugar_die();
    }

    }


    you can use this code in your module where you are going to add new custom fields.

    BTW: you have to understand PHP and SQL for doing this.
    Hi pblag

    thank you for your reply, i've tried through your way. The system can check the duplicate info. But I can't find where the "['LBL_PORTAL_DUPLICATE_USER_NAME']" is defined.

  4. #4
    tina2007 is offline Sugar Community Member
    Join Date
    Apr 2007
    Posts
    26

    Default Re: indicates for improper information in special field

    I have done it, but the result is not what i expected. How can I get the same result like in Contact module?
    Attached Images Attached Images   

  5. #5
    pblag's Avatar
    pblag is offline Sugar Community Member
    Join Date
    Jul 2006
    Location
    Ukraine (Chernivtsy)
    Posts
    347

    Default Re: indicates for improper information in special field

    Hi All!

    I do apologize but i had posted wrong code

    there should be function


    function checkForDuplicates($prefix){
    global $local_log;
    require_once('include/formbase.php');
    require_once('modules/Contacts/Contact.php');
    $focus = new Contact();
    $query = '';
    $baseQuery = 'select id,first_name, last_name, title, email1, email2 from contacts where deleted!=1 and (';
    if(!empty($_POST[$prefix.'first_name']) && !empty($_POST[$prefix.'last_name'])){
    $query = $baseQuery ." (first_name like '". $_POST[$prefix.'first_name'] . "%' and last_name = '". $_POST[$prefix.'last_name'] ."')";
    }else{
    $query = $baseQuery ." last_name = '". $_POST[$prefix.'last_name'] ."'";
    }
    if(!empty($_POST[$prefix.'email1'])){
    if(empty($query)){
    $query = $baseQuery. " email1='". $_POST[$prefix.'email1'] . "' or email2 = '". $_POST[$prefix.'email1'] ."'";
    }else {
    $query .= "or email1='". $_POST[$prefix.'email1'] . "' or email2 = '". $_POST[$prefix.'email1'] ."'";
    }
    }
    if(!empty($_POST[$prefix.'email2'])){
    if(empty($query)) {
    $query = $baseQuery. " email1='". $_POST[$prefix.'email2'] . "' or email2 = '". $_POST[$prefix.'email2'] ."'";
    }else{
    $query .= "or email1='". $_POST[$prefix.'email2'] . "' or email2 = '". $_POST[$prefix.'email2'] ."'";
    }

    }

    if(!empty($query)){
    $rows = array();
    global $db;
    $result = $db->query($query.')');
    $i=-1;
    while (($row= $db->fetchByAssoc($result)) != null) {
    ++$i;
    $rows[$i]=$row;
    }
    if ($i==-1) return null;
    else return $rows;
    }
    return null;
    }



    end function executing

    $duplicateContacts = $this->checkForDuplicates($prefix);
    if(isset($duplicateContacts)){
    $get='module=Contacts&action=ShowDuplicates';


    if(isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
    $get .= '&inbound_email_id='.$_POST['inbound_email_id'];
    }

    //add all of the post fields to redirect get string
    foreach ($focus->column_fields as $field)
    {
    if (!empty($focus->$field))
    {
    $get .= "&Contacts$field=".urlencode($focus->$field);
    }
    }

    foreach ($focus->additional_column_fields as $field)
    {
    if (!empty($focus->$field))
    {
    $get .= "&Contacts$field=".urlencode($focus->$field);
    }
    }

    //create list of suspected duplicate contact id's in redirect get string
    $i=0;
    foreach ($duplicateContacts as $contact)
    {
    $get .= "&duplicate[$i]=".$contact['id'];
    $i++;
    }

    //add return_module, return_action, and return_id to redirect get string
    $get .= "&return_module=";
    if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
    else $get .= "Contacts";
    $get .= "&return_action=";
    if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
    else $get .= "DetailView";
    if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
    if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
    if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];

    // for InboundEmail flow
    if(!empty($_POST['start'])) $get .= '&start='.$_POST['start'];
    //now redirect the post to modules/Contacts/ShowDuplicates.php
    if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1')
    {
    $json = getJSONobj();
    echo $json->encode(array('status' => 'dupe',
    'get' => $get));
    }
    else {
    if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
    header("Location: index.php?$get");
    }
    return null;
    }
    Petro Blagodir
    petro@blagodir.ua
    http://www.blagodir.com
    Blagodir Ltd.( SugarCRM - Consultations, Development and Support)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. custom field to sugar field
    By tanhaa in forum Developer Help
    Replies: 2
    Last Post: 2011-05-04, 03:52 PM
  2. indicates for improper information in special field
    By goodharry in forum Developer Help
    Replies: 0
    Last Post: 2007-04-27, 12:14 PM
  3. Custom required field in User information section
    By Victor Rosillo in forum Help
    Replies: 0
    Last Post: 2007-02-23, 06:29 PM
  4. Replies: 0
    Last Post: 2005-11-23, 01:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •