jQuery Validate wp_editor

时间:2013-05-15 作者:Nick Passaro

我有一个表单,在表单中,我使用

<?php wp_editor(\'\', \'user_submitted_progress\', $settings = array(\'textarea_name\' => \'user_submitted_progress\')); ?>
生成一个TinyMCE,而不是一个简单的textarea. 问题是我无法通过jQuery验证来验证wp\\U编辑器。这是我的jQuery验证代码

$(document).ready(function() {
    $("#user_submitted_post").validate({

        errorPlacement: function(error, element) {},

        debug: false,
        rules: {
            user_submitted_title: {required: true},
            user_submitted_progress: {required: true},
            user_submitted_goals: {required: true},
            user_submitted_categories: {required: true},
            user_submitted_tags: {required: true},
        },

        invalidHandler: function(form, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
                $("#error-message").show().text("Please make sure that all required fields have been filled out.");
            } else {
                $("#error-message").hide();
            }
        },

        submitHandler: function(form) {
            tinyMCE.triggerSave();
            var serialized = $(form).serialize();
            console.log(serialized);
            $(form).ajaxSubmit();
        }

    })
})
这是我的表格:

<?php if (is_user_logged_in()) { ?>

    <div id="error-message"></div>

    <form id="user_submitted_post" action="" method="POST" enctype="multipart/form-data">

        <h2>Title</h2>
        <input type="text" id="user_submitted_title" name="user_submitted_title" value="">

        <p>Please provide detailed information about the long-term goals of your project, as well as your current project progress. Feel free to format your text using boldness, italics, lists, and block quotes. Simply click on the formatting option you\'d like to use and start typing. When you no longer need the format you have selected, hit enter to go to the next line, and click on the active format button to end formatting.</p>

        <h2>Project Progress</h2>
        <?php wp_editor(\'\', \'user_submitted_progress\', $settings = array(\'textarea_name\' => \'user_submitted_progress\', \'media_buttons\' => false, \'quicktags\' => false, \'textarea_rows\' => 15, \'editor_css\' => \'<style type="text/css">.wp_themeSkin .mceListBox .mceText {width: 81px;} .wp_themeSkin table.mceToolbar {margin: 5px;} td.mceToolbar > div {height: inherit;} tr.mceLast {display: none;} .wp_themeSkin .mceButton {margin: 1px 12px;}</style>\', \'tinymce\' => add_filter("mce_buttons", "base_extended_editor_mce_buttons", 0), add_filter("mce_buttons_2", "base_extended_editor_mce_buttons_2", 0)) ); ?>

        <h2>Project Goals</h2>
        <?php wp_editor(\'\', \'user_submitted_goals\', $settings = array(\'textarea_name\' => \'user_submitted_goals\', \'media_buttons\' => false, \'quicktags\' => false, \'textarea_rows\' => 15, \'tinymce\' => add_filter("mce_buttons", "base_extended_editor_mce_buttons", 0), add_filter("mce_buttons_2", "base_extended_editor_mce_buttons_2", 0)) ); ?>

        <h2>Category</h2>
        <?php wp_dropdown_categories($args = array(\'selected\' => Uncategorized, \'orderby\' => \'name\', \'hide_empty\' => 0, \'hierarchical\' => 1, \'id\' => \'user_submitted_categories\', \'name\' => \'user_submitted_categories\')); ?>

        <h2>Tags</h2>
        <p>Separate tags with commas.</p>
        <input type="text" id="user_submitted_tags" name="user_submitted_tags" value="">

        <h2>Video</h2>
        <p>Copy and paste links from Youtube and Vimeo in the field below</p>
        <textarea id="user_submitted_video" name="user_submitted_video"></textarea>

        <h2>Audio</h2>
        <p>Copy and paste links from Soundcloud in the field below</p>
        <textarea id="user_submitted_audio" name="user_submitted_audio"></textarea>

        <h2>Images</h2>
        <input type="file" name="upload_attachment[]" multiple="multiple">

        <?php wp_nonce_field(\'post_nonce\', \'post_nonce_field\'); ?>

        <button type="submit" name="submitbutton" id="submitbutton">Submit</button>

    </form>

<?php } else { ?>

    <?php echo \'Sorry, but you need to be logged in to see that. You can <a href="\'; ?>
    <?php echo wp_login_url( get_permalink() ); ?>
    <?php echo \'" title="Login">login here</a>\'; ?>

<?php } ?>
我如何获得.validate 验证用户在wp\\U编辑器中键入的文本?不要介意wp\\u编辑器的疯狂长数组。我只是把所有的css都放在这个数组中,因为我仍然在测试所有这一切,在2012年的主题中。

非常感谢您的帮助。

1 个回复
SO网友:Pat J

根据jQuery noConflict Wrappers 第节wp_enqueue_script() Codex页$ 变量在WordPress中不可用。您可以替换$ 具有jQuery 在jQuery代码中,或执行以下操作:

jQuery(document).ready(function($) {
    // your code here
    .
    .
    .
});

结束

相关推荐

WordPress窗口小部件缺少jQuery

我有live score网站,它不是基于wordpress的,我为纯php网站构建了一个小部件,但现在我想向wordpress用户提供这个小部件。问题是,当我尝试这个小部件时,我出现了三个错误,老实说,我不是wordpress专家,所以我希望在这里得到帮助。这是我的用户链接:<div id=\"widget-container\" class=\"my_widget\" name=\'15\' width=\"800px\"></div> <script src=\"