WordPress.org

Ready to get started?Download WordPress

Forums

modify the content of comment on submit (1 post)

  1. jcm
    Member
    Posted 6 years ago #

    My aim is to get a comment with that format: title<!iiTITLE -->content

    I made a filter in function.php to display correctly these comments.

    I have to make one when a user submits the comment. Problem, I also use ajax. So the FORM is: `<form
    id="awpsubmit_commentform_<?php echo $id;?>"
    class="comment_form"
    action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php"
    method="post"
    onsubmit="<?php title_filter($onsubmit);echo apply_filters('awp_commentform_on_submit',$on_submit); //Leave for AWP features?>"
    >`

    the apply_filter is for ajax, which then redirect to wp_comments_post.php.

    my filters in function.php:

    global $titre;
    add_filter('comment_text','comment_filter');
    add_filter('pre_comment_content','ajoute_titre');
    function comment_filter($content) {
    $i=strpos($content,'<--!TITLE -->');
    if ($i){
    $title='<h3>'.substr($content,0,$i).'</h3>';
    $texte=substr($content,$i+13);
    
    }
    else{
    $title='<h3>'.__('Without Object','stendhal').'</h3>';
    $texte=$content;
    }
    $content=$title.$texte;
    return $content;
    }
    
    function ajoute_titre($content) {
    $content=$titre.'<!--TITLE -->'.$content;
    return $content;
    }
    
    function title_filter($on_submit) {
    $titre = trim($_POST['titre']);
    }

    Og course, it doesn't work. Some help?

Topic Closed

This topic has been closed to new replies.

About this Topic