• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wpcf_form_add_js_validation函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wpcf_form_add_js_validation函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_form_add_js_validation函数的具体用法?PHP wpcf_form_add_js_validation怎么用?PHP wpcf_form_add_js_validation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wpcf_form_add_js_validation函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: renderElement

 /**
  * Renders element.
  *
  * Depending on element type, it calls class methods.
  *
  * @param array $element
  * @return HTML formatted output
  */
 public function renderElement($element)
 {
     $method = $element['#type'];
     if (!isset($element['#name']) && $element['#type'] != 'markup') {
         if (!isset($element['#attributes']['name'])) {
             return '#name or #attributes[\'name\'] required!';
         } else {
             $element['#name'] = $element['#attributes']['name'];
         }
     }
     if (is_callable(array($this, $method))) {
         if (!isset($element['#id'])) {
             if (isset($element['#attributes']['id'])) {
                 $element['#id'] = $element['#attributes']['id'];
             } else {
                 $element['#id'] = $element['#type'] . '-' . $this->_count($element['#type']);
             }
         }
         if (isset($this->_errors[$element['#id']])) {
             $element['#error'] = $this->_errors[$element['#id']];
         }
         // Add JS validation
         if (!empty($element['#validate'])) {
             wpcf_form_add_js_validation($element);
         }
         return $this->{$method}($element);
     }
 }
开发者ID:Netsoro,项目名称:gdnlteamgroup,代码行数:36,代码来源:forms.php


示例2: fields_js

    /**
     * Returns formatted JS.
     * 
     * @param type $selector Can be CSS class or element ID
     * @return string
     */
    function fields_js($selector = '.wpcf-form-validate')
    {
        // Get collected validation rules
        $elements = wpcf_form_add_js_validation('get');
        // Not collected!
        if (empty($elements)) {
            return '';
        }
        /*
         * Start output
         */
        $output = '';
        /*
         * Open tags and trigger jQuery validation.
         */
        $output .= "\r\n" . '<script type="text/javascript">' . "\r\n" . '/* <![CDATA[ */' . "\r\n" . 'jQuery(document).ready(function(){' . "\r\n" . 'if (jQuery("' . $selector . '").length > 0){' . "\r\n" . 'jQuery("' . $selector . '").validate({
        errorPlacement: function(error, element){
            error.insertBefore(element);
        },
        highlight: function(element, errorClass, validClass) {
            jQuery(\'#publishing-action .spinner\').css(\'visibility\', \'hidden\');
            jQuery(\'#publish\').bind(\'click\', function(){
                jQuery(\'#publishing-action .spinner\').css(\'visibility\', \'visible\');
            });
            jQuery(element).parents(\'.collapsible\').slideDown();
            ';
        if ($selector == '#post') {
            $output .= 'var box = jQuery(element).parents(\'.postbox\');
                if (box.hasClass(\'closed\')) {
                    box.find(\'.handlediv\').trigger(\'click\');
                    }';
        }
        $output .= '
            jQuery(element).parents(\'.collapsible\').slideDown();
            jQuery("input#publish").addClass("button-primary-disabled");
            jQuery("input#save-post").addClass("button-disabled");
            jQuery("#save-action .ajax-loading").css("visibility", "hidden");
            jQuery("#publishing-action #ajax-loading").css("visibility", "hidden");
//            jQuery.validator.defaults.highlight(element, errorClass, validClass); // Do not add class to element
		},
        unhighlight: function(element, errorClass, validClass) {
			jQuery("input#publish, input#save-post").removeClass("button-primary-disabled").removeClass("button-disabled");
//            jQuery.validator.defaults.unhighlight(element, errorClass, validClass);
		},';
        /*
         * jQuery invalidHandler
         * http://docs.jquery.com/Plugins/Validation/validate#toptions
         * 
         * Since Types 1.1.5 we apply filters on invalid handler
         */
        $additional_js = apply_filters('wpcf_validation_js_invalid_handler', '', $elements, $selector, array('form', 'validator'));
        $output .= '
        invalidHandler: function(form, validator) {
        
            elements = new Array();
        
            // validator.errorList contains an array of objects, where each object has properties "element" and "message".  element is the actual HTML Input.
            for (var i=0;i<validator.errorList.length;i++){
                var el = validator.errorList[i].element;
                elements.push(jQuery(el).attr(\'id\'));
            }

            // validator.errorMap is an object mapping input names -> error messages
            //    for (var i in validator.errorMap) {
            //      console.log(i, ":", validator.errorMap[i]);
            //    }

            var form = jQuery(\'' . $selector . '\');
            var passed = false;
            ' . $additional_js . '
//            alert(passed);
            if (passed) {
                jQuery(\'' . $selector . '\').validate().cancelSubmit = true;
                jQuery(\'' . $selector . '\').submit();
            }
        },
        ';
        $output .= 'errorClass: "wpcf-form-error"';
        $output .= '});' . "\r\n";
        /*
         * 
         * 
         * Render JS validation code for each element collected
         */
        foreach ($elements as $id => $element) {
            // Basic check
            if (empty($element['#validate'])) {
                continue;
            }
            /*
             * 
             * Adjust rules according to field type
             * 
             * TODO Document why radios selects 'name' instead of 'id'
//.........这里部分代码省略.........
开发者ID:adisonc,项目名称:MaineLearning,代码行数:101,代码来源:javascript.php


示例3: wpcf_form_render_js_validation

/**
 * Renders JS validation rules.
 * 
 * @return type 
 */
function wpcf_form_render_js_validation($form = '.wpcf-form-validate', $echo = true)
{
    //    static $cache;
    //    if (($echo && isset($cache[$form]['echo'])) || (!$echo && isset($cache[$form]['return']))) {
    //        return '';
    //    }
    $elements = wpcf_form_add_js_validation('get');
    if (empty($elements)) {
        return '';
    }
    $output = '';
    $output .= "\r\n" . '<script type="text/javascript">' . "\r\n" . '/* <![CDATA[ */' . "\r\n" . 'jQuery(document).ready(function(){' . "\r\n" . 'if (jQuery("' . $form . '").length > 0){' . "\r\n" . 'jQuery("' . $form . '").validate({
        errorClass: "wpcf-form-error",
        errorPlacement: function(error, element){
            error.insertBefore(element);
        },
        highlight: function(element, errorClass, validClass) {
            jQuery(element).parents(\'.collapsible\').slideDown();
            jQuery("input#publish").addClass("button-primary-disabled");
            jQuery("input#save-post").addClass("button-disabled");
            jQuery("#save-action .ajax-loading").css("visibility", "hidden");
            jQuery("#publishing-action #ajax-loading").css("visibility", "hidden");
//            jQuery.validator.defaults.highlight(element, errorClass, validClass); // Do not add class to element
		},
        unhighlight: function(element, errorClass, validClass) {
			jQuery("input#publish, input#save-post").removeClass("button-primary-disabled").removeClass("button-disabled");
//            jQuery.validator.defaults.unhighlight(element, errorClass, validClass);
		},
    });' . "\r\n";
    foreach ($elements as $id => $element) {
        if (empty($element['#validate'])) {
            continue;
        }
        if (in_array($element['#type'], array('radios'))) {
            $output .= 'jQuery(\'input:[name="' . $element['#name'] . '"]\').rules("add", {' . "\r\n";
        } else {
            $output .= 'jQuery("#' . $id . '").rules("add", {' . "\r\n";
        }
        $rules = array();
        $messages = array();
        foreach ($element['#validate'] as $method => $args) {
            if (!isset($args['value'])) {
                $args['value'] = 'true';
            }
            $rules[] = $method . ': ' . $args['value'];
            if (empty($args['message'])) {
                $args['message'] = wpcf_admin_validation_messages($method);
            }
        }
        $output .= implode(',' . "\r\n", $rules);
        if (!empty($messages)) {
            $output .= ',' . "\r\n" . 'messages: {' . "\r\n" . implode(',' . "\r\n", $messages) . "\r\n" . '}';
        }
        $output .= "\r\n" . '});' . "\r\n";
    }
    $output .= "\r\n" . '/* ]]> */' . "\r\n" . '}' . "\r\n" . '})' . "\r\n" . '</script>' . "\r\n";
    if ($echo) {
        //        $cache[$form]['echo'] = 1;
        echo $output;
    } else {
        //        $cache[$form]['return'] = 1;
        return $output;
    }
}
开发者ID:sriram911,项目名称:pls,代码行数:69,代码来源:admin.php


示例4: renderJsonData

    /**
     * Returns formatted JSON validation data.
     * 
     * @param type $selector Can be CSS class or element ID
     * @return string
     */
    static function renderJsonData($selector = '.wpcf-form-validate')
    {
        // Get collected validation rules
        $elements = wpcf_form_add_js_validation('get');
        // Not collected!
        if (empty($elements)) {
            return '';
        }
        $json = array('selector' => $selector, 'elements' => array());
        foreach ($elements as $id => $element) {
            // Basic check or skip read-only
            if (empty($element['#validate']) || isset($element['#attributes']['readonly'])) {
                continue;
            }
            $json['elements'][$id] = array('id' => $id);
            // Set selectors
            if (in_array($element['#type'], array('radios'))) {
                $json['elements'][$id]['selector'] = "input[name=\"{$element['#name']}\"]";
            } else {
                $json['elements'][$id]['selector'] = "#{$id}";
            }
            foreach ($element['#validate'] as $method => $args) {
                $args['value'] = !isset($args['value']) ? 'true' : $args['value'];
                if (empty($args['message'])) {
                    $args['message'] = wpcf_admin_validation_messages($method, $args['value']);
                }
                //Check if wordpress date format is d/m/Y and use ITA validation
                if ($method == 'date' && isset($element['wpcf-type']) && $element['wpcf-type'] == 'date' && get_option('date_format') == 'd/m/Y') {
                    $method = 'dateITA:true';
                }
                // Set JSON data
                $json['elements'][$id]['rules'][] = array('method' => $method, 'value' => $args['value'], 'message' => $args['message']);
            }
        }
        ob_start();
        ?>

        <script type="text/javascript">
            //<![CDATA[
            types.validation.push(<?php 
        echo json_encode($json);
        ?>
);
            <?php 
        if (defined('DOING_AJAX')) {
            ?>
            jQuery(document).ready(function($) {
                typesValidation.setRules();
            });
        <?php 
        }
        ?>
            /* ]]> */
        </script>

        <?php 
        $output = ob_get_contents();
        ob_get_clean();
        wp_enqueue_script('types-validation');
        return $output;
    }
开发者ID:aarongillett,项目名称:B22-151217,代码行数:67,代码来源:validation.php



注:本文中的wpcf_form_add_js_validation函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wpcf_form_render_js_validation函数代码示例发布时间:2022-05-23
下一篇:
PHP wpcf_form函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap