I unsuccessfully tried https://www.drupal.org/project/rules_forms for forms validation so I am writing my own little validation module.
Basically, on node creation I want a validation against a custom user profile field (machine name: field_points). When the user enters on node creation more points then he has on his profile, an error message should appear.
Static validation against a number works just fine, but how can I access custom fields of the user object? Using devel, for some reason they don't show up in dpm($user).
function custom2_form_contenttype_node_form_alter(&$form, &$form_state, &$form_id) {
drupal_set_message("Form ID is : " . $form_id);
dpm($form);
//$form['field_points']['und']['0']['value']['#default_value'] = 164;
$form['#validate'][] = 'custom2_form_contenttype_node_form_validate';
}
function custom2_form_contenttype_node_form_validate($form, $form_state) {
global $user;
dpm($user);
$profilePoints = $user->field_points;
$enteredPoints = $form_state['values']['field_points']['und']['0']['value'];
dpm($form['#validate']);
dpm($form_state);
if ($enteredPoints > $profilePoints) {
form_set_error('field_points', '"You can only spend" . $profilePoints . " //points."');
}
}
EDIT: uploaded devel user screenshot