Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By fudge714 on
I have no idea what happened, but hook_form_alter suddenly stopped working while I was doing some editing (not in that function). I reverted all my changes anyway and nothing changed, I'm still just getting the same original version of the form. the forums suggested it could be a cache issue, but I've cleared my cache and also tried it in a different browser and its still the same original form.
anyone have any ideas?
Comments
Code Details Please...
Hi There,
First thing you need to check is...
1) Your Module is enabled or not !
If it is enabled then, Can you paste your module code here, so we can take a look ?
code
Hi,
yes it is enabled. and thanks for taking a look, here is the code..
Is Form Id is printing fine
Is Form Id is printing fine inside ?
inside where?
what do you mean?
not printing
just uncommented the stuff to print the form array inside hook_alter if thats what you mean, and its not printing. it seems as if the function is just not getting called. i also tried printing something before the form_id if, and it didn't print that either
Form_Alter Not Called.
Hey,
Just some quick observations.
1) You have not defined $form_state properly, Its a reference to $form_state represented as &$form_state.
2) In your hook_node_insert, You have written node_save() . I doubt if that should be written inside, cause hook_node_insert() is called by node_save() itself. I think this is becoming a infinite loop.
3) You can try commenting everything in this file except form_alter, Specially the node_hooks (Presave and insert) .
Please correct step 1. And let us know if form_alter got called.
Question : Where have you written this hook_form_alter() ?, Is it in one of your Inc files ?
P.S : There could be a possibility that you have defined your hook name "diolibrary_form_alter" TWICE, once in your .module file and other in your inc file or something like that, This is just a guess :)
context
I'm guessing its not anything to do with the code though, since it was working at the start of the night and even if I upload the file from that time, it still doesn't work.
In case its useful though, tonight I was mainly editing in the node_insert function
oh and if a bit of context might be useful for reading the code, its basically a module for a library cataloging system. The main thing is changing the form so that multiple items can be added at once, and grabbing all the data from websites from the isbn which we can input easily with a barcode scanner.
Hi fudge714,
Hi fudge714,
As what kunal.kursija suggested, you could try commenting all of the functions inside your module file except the hook_form_alter. Then comment all of your code inside the hook_form_alter then try to put
drupal_set_message($form_id); only.
If it shows the form_id in all the forms you are hitting then your hook_form_alter is working fine. Then try uncommenting your functions one by one , see if your form alter still works, and to verify what is causing the trouble.
You could also try using hook_form_FORM_ID_alter() as an alternative.
And also don't forget to pass $form_state by reference (&$form_state), make sure your module is enabled, you are using the correct module name in your hooks, no duplicate form alters, and clear caches from time to time.
Regards,
leramos
it was the cache
thanks guys, turned out I was only clearing my browser cache and not the server cache and that did it.
and thanks for pointing out the other issues as well..