I am using entity registrations to let users register to an event. I have some fields that I want to validate depending on the value of other fields.
So, using hook_form_id_form_alter, i was able to add a second validation function. The second function is where i hoped I can add the code for validating the registration form.
function coastal_custom_form_registration_form_alter($form, &$form_state, $form_id) {
$form['#validate'][] = 'event_registration_form_validate';
}
But whenever I submit the form, the function that is supposed to do the validation never gets called.
//this function never gets called
function event_registration_form_validate(&$form, &$form_state){
drupal_set_message('hi from validation');
form_set_error('you are in form_registration');
}
I have been figuring how to do this for the whole day. Have anyone figured out how this is done? Thanks.
Reading the api documentation on hook_form_alter, I found out that you have to pass by reference $form. So the correct way of writing the function should be:
Take note that there is an ampersand (&) before the $form variable.