S
S
SergeyRey2014-11-25 14:43:54
Drupal
SergeyRey, 2014-11-25 14:43:54

How to make a different field value for different roles?

Good day.
Site on Drupal 7.
There is a field for uploading an image. I would like to allow registered users to upload 6 files, and anonymous users 2.
I found this code:
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'name_node_form') {
array_unshift( $form['#validate'], 'addtonal_validate');
}
}
function addtonal_validate($form, $form_state {
$count = 0;
foreach($form_state['values']['field_img'] as $img) {
if (!empty($img['value'])) {
$count++;
}
}
global $user;
if (in_array('anonymous_user', $user->roles)) {
if ($count > 2) {
form_set_error('field_img', t('You cannot upload more than 2 img'));
}
}
}
?>
I insert it into my module, replace it with my own values, but nothing works. Tell me, maybe something is wrong in the code or there are other approaches?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question