简体   繁体   中英

validate CKEditor with jQuery Validation plugin

how to validate CKeditor with jQuery validation plugin.

This is my code

<script type="text/javascript">
    $(document).ready(function(){
        $("#newpost").validate({
            debug: false,
            rules: {
                title: "required",
                cat_id: "required",
                editor1:"required"
            },
            messages: {
                title: "  Title name cannot be blank.",
                cat_id: "  Please select a category.",
                editor1: "  Post keywords cannot be blank."         
            },
            submitHandler: function(form) {
                // do other stuff for a valid form
                $.post('new_post.php', $("#newpost").serialize(), function(data) {
                 $('#msgw').html(data);
                });             
            }
        });
    });
    </script>

PHP code:

<?php
include ('../db.php');

$title = mysql_real_escape_string($_POST['title']);
$editor1 = $_POST['editor1'];
$date= date("Y-m-d");
$cat_id = mysql_real_escape_string($_POST['cat_id']);


$qu = mysql_query("INSERT INTO blogposts(title,post,date,catid)VALUES ('".$title."','".$editor1."','".$date."','".$cat_id."')") or die (mysql_error());
?>

problem is it dosent even post the contain in the editor. how can i fix this problem. thank you.

I have added this code below:

CKEDITOR.instances.pdetails.updateElement();

pdetails is the name of your textarea. And when you try to submit your form and print out the the textarea:

$pdetails = $_POST['pdetails'];

print $pdetails;

make sure it has a value before you have tested it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM