douyanjing0822 2017-03-31 15:41
浏览 48

vTiger自定义字段验证beforesave

I have created a custom module on vTiger 6.5.

I have made an event handler for the module but I am wondering how I could perform some sort of validation on this field. So fat I have done this but I am unable to get it work, I have tested the handler just echoing a sting and it works fine.

Please see my code below. Thanks!

    <?php
/*+***********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 *************************************************************************************/
# getModuleName : Returns the module name of the entity.
# getId : Returns id of the entity, this will return null if the id has not been saved yet.
# getData : Returns the fields of the entity as an array where the field name is the key and the fields value is the value.
# isNew : Returns true if new record is being created, false otherwise. 
# 'vtiger.entity.beforesave.modifiable' : Setting values : $data->set('simple_field', 'value'); 

class isaHandler extends VTEventHandler { 
    function handleEvent($eventName, $entityData) {
        global $adb;
        $moduleName = $entityData->getModuleName(); 
        if($moduleName=='isa'){     
            if($eventName == 'vtiger.entity.beforesave.modifiable') {}
            if($eventName == 'vtiger.entity.beforesave') {
                if('currentamount' > 20000){
                    echo "Please go back and enter less than 20000";
                exit;
                }

            }
            if($eventName == 'vtiger.entity.beforesave.final') {}
            if($eventName == 'vtiger.entity.aftersave') {
            }
        }   
    }

}
?>
  • 写回答

3条回答 默认 最新

  • dongyong1897 2017-03-31 16:41
    关注

    After doing some searching around and looking at other peoples event handlers I managed to solve this by changing:

    if($eventName == 'vtiger.entity.beforesave') {
                    if('currentamount' > 20000){
                        echo "Please go back and enter less than 20000";
                    exit;
                    }
    

    to

    if($eventName == 'vtiger.entity.beforesave') {
                    $price = $entityData->get('currentamount');
                    if($price > 20000){
                        echo "Please go back and enter less than 20000";
                    exit;
                    }
    

    Now I want to see if I can display the message and then give a link to go back to the entity module with all the fields still full.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值