3

I've tried to create a validation and submit functions on a custom comment form, using drupal 7.9, but it's not working, and I don't know why.

In the following code, we can see the "dpm's" in the first function, but not the "dpm's" in the last ones.

function job_form_comment_node_job_form_alter(&$form, &$form_state) {
    $form['#validate'][] = 'job_comment_validate';
    $form['#submit'][] = 'job_comment_submit';
    dpm($form);
    dpm($form_state);
}


function job_comment_validate($form, &$form_state) {
    dpm($form);
    dpm($form_state);
}

function job_comment_submit($form, &$form_state) {
    dpm($form);
    dpm($form_state);
}

if I add a #validate or #submit it also doesn't call others drupal hook comments like presave, insert etc.

If I comment these lines, the hooks are called, but I can't use the validation or the submission functions in this case.

Do you have any idea on why this happens?

5
  • 1
    Do you have any module that defines the comment_node_job_form() function?
    – apaderno
    Nov 4, 2011 at 19:31
  • No, I have not.
    – Antonio
    Nov 4, 2011 at 20:59
  • Does the comment get saved when the form is submitted? Also, what you can see in #submit when you dpm
    – AKS
    Dec 17, 2012 at 6:16
  • Just to be clear, you wouldn't see the dpms from the validate and submit functions until you actually submitted the form. You're not expecting to see them when you just load the page, are you? May 2, 2013 at 20:17
  • you have job_from_....alter then you have ` job_comment_validate` and job_comment_submit...1. whats your module name? 2. Can you post the implementation the define the comment_node_job_form form.. should be function comment_node_job_form.. if you do not have, then your alter function is not altering anything ..
    – awm
    Mar 12, 2014 at 16:45

1 Answer 1

-1

You're missing $form_id, the third parameter of the function.

See hook_form_alter() reference on drupal.org. The problem you're experiencing might be a (weird) way of PHP reacting to that.

In situations like this you may want to check for errors on the logs (Drupal, PHP, MySQL). Some times there are useful hints there to figure what's wrong.

2
  • No, I can specify a hook for hook_form_alter in both ways. Either using the $form_id as the third parameter or using the following signature hook_form_ +form_id+ _alter(&$form, &$form_state), the proof is that I can see the dpm's in the first functions. I've already tried to try to use your hook signature and I have exactly the same result.
    – Antonio
    Nov 5, 2011 at 12:40
  • 3
    It is not necessary to use $form_id in hook_form_FORM_ID_alter(), as that hook is only called for the form with ID equal to "FORM_ID."
    – apaderno
    Nov 5, 2011 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.