在 Sugarcrm 中进行现场验证 [英] Field validations in sugarcrm

查看:21
本文介绍了在 Sugarcrm 中进行现场验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次开始使用 SugarCRM CE(版本 6.5.15 (Build 1083)).添加新字段或模块时的易用性给我留下了深刻的印象,但似乎缺少一项不可或缺的东西:用户输入的验证.

I just started using SugarCRM CE for the first time (Version 6.5.15 (Build 1083)). I'm quite impressed with the ease of use when adding new fields or modules, but there's one quite indispensable thing that seems to be missing: Validation of user input.

例如,我想检查很多东西:

I would for example like to check a lot of things:

  • 使用正则表达式检查 emailadres 是否具有有效格式
  • 检查邮政编码是否存在(可能会调用网络服务来验证它)
  • 计算一下公民服务号码是否有效

我在工作室中似乎唯一能做的就是设置一个字段是否为必填字段,似乎没有任何标准方法可以在字段上执行验证.

The only thing I seem to be able to do in studio is make a field required or not, there doesn't seem to be any standard way to execute a validation on a field.

当我在谷歌上搜索时,我能找到很多方法来破解源代码,比如这个:http://phpbugs.wordpress.com/2010/01/22/sugarcrm-adding-javascript-validation-on-form-submit/ 即便如此,我也没有找到任何实际进行验证的示例.

All I can find when I google on it is lots of ways to hack into the source code, like this one: http://phpbugs.wordpress.com/2010/01/22/sugarcrm-adding-javascript-validation-on-form-submit/ And even then I don't find any examples that actually do a validation.

我是不是错过了什么?或者编辑源代码是添加这个的唯一方法?

Am I just missing something? Or is editing source code the only way to add this?

推荐答案

我认为 CE 版本中不提供标准"验证.

I don't think the "standard" validations are available in the CE edition.

令我惊讶的是,您无法在某处定义验证并将其附加到字段.我有点预料到这一点,因为系统的其余部分结构非常好(模块、包等.)

What surprises me is that you can't define a validation somewhere and attach it to a field. I kind of expected this, since the rest of the system is very well structured (modules, packages, etc..)

例如,我现在创建了一张 11-check,这是针对荷兰银行帐号的非常具体的支票.为了让它起作用,我做了以下事情(基于我在谷歌上搜索到的例子):

I now for instance created a 11-check, this is a very specific check for a dutch bank account number. to get this to work, I did the following (based upon examples I found googling around):

我将银行帐户添加到工作室中的联系人,然后编辑了 \custom\modules\Contacts\metadata\editviewdefs.php

I added the bank account to contacts in studio and after that edited \custom\modules\Contacts\metadata\editviewdefs.php

我添加了以下片段:

'includes'=> array(
        array('file'=>'custom/modules/Contacts/customJavascript.js')),




array (
         0 =>
          array(
           'customCode' =>
            '<input title="Save [Alt+S]" accessKey="S" onclick="this.form.action.value=\'Save\'; return check_custom_data();" type="submit" name="button" value="'.$GLOBALS['app_strings']['LBL_SAVE_BUTTON_LABEL']>',
          ),
         1 =>
          array(
           'customCode' =>
            '<input title="Cancel [Alt+X]" accessKey="X" onclick="this.form.action.value=\'index\'; this.form.module.value=\''.$module_name.'\'; this.form.record.value=\'\';" type="submit" name="button" value="'.$GLOBALS['app_strings']['LBL_CANCEL_BUTTON_LABEL'].'">'
          )
        ),

在 customJavascript.js 中,我放置了这段代码:

And in customJavascript.js i placed this code:

function check_custom_data()
{
    if (!eleven_check(document.getElementById("bankaccount_c").value)){
        alert ('Bank account not valid');
        return false;
    } else {
      return check_form('EditView');
    }

    function eleven_check(bankaccount) {
    bankaccount=bankaccount.replace(/\D/, "");
    charcount=bankaccount.length;
    var som=0;
    for (i=1; i<10; i++) {
        getal=bankaccount.charAt(i-1);
        som+=getal*(10-i);
    } 
    if (som % 11==0 && charcount==9) {
        return true
    } else {
        return false
    }
}

}

此检查现在按我希望的方式工作,但我想知道这是否是添加验证的最佳方式.然而,这种添加验证的方式并不能适应 PHP 验证,例如,如果我出于某种或其他原因想针对数据库中的某些数据进行验证,我将不得不使用 ajax 调用来完成这项工作.

This check now works the way I want it to work, but I'm wondering if this is the best way to add a validation. this way of adding a validation doesn't however accommodate PHP validations, for instance, if I want to validate against some data in the database for one or another reason, I would have to use ajax calls to get that done.

这篇关于在 Sugarcrm 中进行现场验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆