WordPress.org

Ready to get started?Download WordPress

Forums

Custom Field Suite
New field type email and validate it (4 posts)

  1. Nilambar Sharma
    Member
    Posted 5 months ago #

    Hello,
    I need a new field type email. I extended cfs_field and made a class ( in a separate add-on plugin). Input data is saved nice but I could not add validation of email. How can I validate it?

    https://wordpress.org/plugins/custom-field-suite/

  2. Nilambar Sharma
    Member
    Posted 5 months ago #

    Can plugin author reply on this please? I want to extend and add new field in CFS.

  3. mgibbs189
    Member
    Plugin Author

    Posted 5 months ago #

    I still need to add another hook before custom validation can be used.

    There's a cfs_custom_validation hook where you define the validation rules, but there needs to be another hook (line ~313 of form.php) to allow you to "attach" a custom rule to fields.

    Here's an example of the cfs_custom_validation hook.

    function prefix_cfs_custom_validation() {
    ?>
    <script>
    (function($) {
        $(function() {
            CFS.validators['valid_email']: {
                'error': 'Please enter a valid email',
                'validate': function(val) {
                    var regex = "THE EMAIL VALIDATION REGEX";
                    return regex.test(val);
                }
            }
            CFS.get_field_value['email'] = function(el) {
                return el.find('input').val();
            }
        });
    })(jQuery);
    </script>
    <?php
    }
    add_action( 'cfs_custom_validation', 'prefix_cfs_custom_validation' );
  4. Nilambar Sharma
    Member
    Posted 5 months ago #

    So you are saying, I need to wait for another version (after adding another hook) to use the above code?

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.