function comment_validate in Drupal 6
Same name and namespace in other branches
- 4 modules/comment.module \comment_validate()
- 5 modules/comment/comment.module \comment_validate()
Validate comment data.
Parameters
$edit: An associative array containig the comment data.
Return value
The original $edit.
1 call to comment_validate()
- comment_form_validate in modules/
comment/ comment.module - Validate comment form submissions.
File
- modules/
comment/ comment.module, line 1183 - Enables users to comment on published content.
Code
function comment_validate($edit) {
global $user;
// Invoke other validation handlers
comment_invoke_comment($edit, 'validate');
if (isset($edit['date'])) {
// As of PHP 5.1.0, strtotime returns FALSE upon failure instead of -1.
if (strtotime($edit['date']) <= 0) {
form_set_error('date', t('You have to specify a valid date.'));
}
}
if (isset($edit['author']) && !($account = user_load(array(
'name' => $edit['author'],
)))) {
form_set_error('author', t('You have to specify a valid author.'));
}
// Check validity of name, mail and homepage (if given)
if (!$user->uid || isset($edit['is_anonymous'])) {
$node = node_load($edit['nid']);
if (variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) > COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
if ($edit['name']) {
$taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']));
if ($taken != 0) {
form_set_error('name', t('The name you used belongs to a registered user.'));
}
}
else {
if (variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MUST_CONTACT) {
form_set_error('name', t('You have to leave your name.'));
}
}
if ($edit['mail']) {
if (!valid_email_address($edit['mail'])) {
form_set_error('mail', t('The e-mail address you specified is not valid.'));
}
}
else {
if (variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MUST_CONTACT) {
form_set_error('mail', t('You have to leave an e-mail address.'));
}
}
if ($edit['homepage']) {
if (!valid_url($edit['homepage'], TRUE)) {
form_set_error('homepage', t('The URL of your homepage is not valid. Remember that it must be fully qualified, i.e. of the form <code>http://example.com/directory</code>.'));
}
}
}
}
return $edit;
}