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';

function job_comment_validate($form, &$form_state) {

function job_comment_submit($form, &$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?

  • 1
    Do you have any module that defines the comment_node_job_form() function? – kiamlaluno Nov 4 '11 at 19:31
  • No, I have not. – Antonio Nov 4 '11 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 '12 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? – Adam Balsam May 2 '13 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 '14 at 16:45

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.

  • 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 '11 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." – kiamlaluno Nov 5 '11 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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