I'm using form_alter to play with the node form for a specific content type. This content type has many different fields and I'm also using Field Collection module to organize all these fields & logic, if that makes any difference.
Apparently, there are some incompatibilities between the Field Collection & Field Dependencies modules so I thought I might be able to build a similar field dependency functionality with my own module.
I've created a validation function for the form. My problem is that I'm trying to access $form_state values that users insert in the form in order to validate these values but I think I'm doing something totally wrong here:
function _mymodule_my_validation_function($form, &$form_state){
$short_field_name = $form_state['values']['long_field_name'];
if (empty($short_field_name) || $$short_field_name == '') {
form_set_error('error','That field cannot be empty!');
}
}
Unfortunately this validation script doesn't work. To be more exact, I
dpm($form_state);
in my form_alter and $form_state doesn't even contain 'values' (shouldn't it be present but empty?).
Is there a different best practice for validation node form fields instead of dealing with the $form_state['values'] array?
Also, I need to be able to see the values submitted by users each time the node form is submitted. Currently, I dpm($form) in my form_alter function and everything is returned on the node/%/edit page as expected. But how can I catch submitted values on the node/% page after submitting the node form??
Update: When I call dpm($form_state) within my validation function I get what I need if the form doesn't validate (as we still are on the same node edit page). But how can I receive the (new/changed) values that users entered in the form fields in case the form is submitted successfully and user is directed to content list page?
dpm
. If you've put it in the main form it will call on page load and be empty. You have putdpm()
in the validate or submit function to see the data you've entered.