문제

I am using MYMODULE_form_comment_form_alter to check comment's body text and I have a validation function:

function MYMODULE_form_comment_form_alter(&$form, &$form_state, &$form_id){
    $form['#validate'][] = 'MYMODULE_comment_form_validate';
}

function MYMODULE_comment_form_validate($form, &$form_state){
    $current_body = $form_state['values']['comment_body'][LANGUAGE_NONE][0]['value'];

    if (strpos($current_body, "www") == TRUE || strpos($current_body, "http") == TRUE) {
        form_set_error($form['comment_body'], "Error message");
    }
}

It is working perfectly but form still submitting values. How can do a function which doesn't submit if comment body value is not valid? Thanks!

도움이 되었습니까?

해결책

Try using form_error() instead of form_set_error().

Let me know whether it worked.

Hope this works... Muhammad.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top