Forum Discussion

jgroves's avatar
jgroves
Expert
11 years ago

Javascript to Execute Before Post

Hi,

I'd like some javascript to execute when a user clicks "post" when either begining a thread or replying. Basically for many complicated reasons (too much detail to provide in this post) we're needing to check the post for a certain character set and if the post or title contains this character set we don't want to allow the user to post. I know the Lithium out of the box content filters do forms of this, but for numerous reasons that will not meet our needs. Does anyone know how I can make this javascript execute upon the "post" action? I'm unsure which API call is best.

 

Thanks,

Jordan

2 Replies

  • Hi Jordan

     

    You can use below jquery code to prevent from submition of form;

     

    Replace "#confirmForm" with class or id of the submit button.

    Replace "#FieldName" with class or id of the field you are using.

     

    $('#confirmForm').submit(function(ev){
    var CharCount = $('#FieldName').val().length;
    if (CharCount > 50) {
    return false;
    }
    });

  • Hi,

     

    The following jquery code might fullfill your needs. 

     

    $('.lia-button-Submit-action').bind('click', function(e) {

    /* perform your validation here */
    var subject = $(".lia-subject");
    if(subject.value.match(/* characters to check */))
    {
    e.preventDefault();
    alert(/* alert user for wrong characters */)
    }else {
    return true;
    }
    };

     

    I have given example to check subject after user click Post button.