Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
12 Mar 2013 at 17:23 UTC
Updated:
29 May 2013 at 06:32 UTC
Jump to comment: Most recent
Comments
Comment #1
pfrenssenHello, thanks for the report. Unfortunately we lack the necessary context to be able to replicate this problem. Please read Tips for making a good issue report and provide enough information so that we can replicate the problem.
Comment #2
roynilanjan commentedAbove snippet is implemented in hook_form_alter() for some customization after form-submit.
Here in the mentioned call back it's try to make some redirection (search_submit)
Now if I'm not doing $form['#action']='' or unset that search_submit is not called at-all.
Please let me know if anything needs to reproduce again
Comment #3
pfrenssenI'm sorry but your code does not make much sense. You are probably using the wrong hook. Your code will alter all forms, sets
#actionto an invalid path and adds a new submit handler to all forms. In addition to this you are not declaring all arguments ($form, $form_state, $form_id), causing you to lose the form state. No wonder that it breaks.I'm guessing you would like to alter one particular form, for example the search form. In this case you need to implement
hook_form_FORM_ID_alter(). The function will get a name likemymodule_form_search_form_alter(). Also take a look at the required parameters.If you need some more information, you can take a look at the article Forms API - Modify Forms with hook_form_alter().
Comment #4
roynilanjan commentedYes code should be under hook_form_FORMID_alter() or under a specific form id in a hook_form_alter().
Now if I'm not doing $form['#action']='' or unset that search_submit is not called at-all.
Is it make any sense? please let me know :)
Comment #5
pfrenssenIf you have trouble working with the form API, I can heartily recommend the Examples for Developers project. It contains many nice well-commented examples of how to use the form API.
To answer your question, in the example you gave you are not using the hook system correctly. The most important thing is that you are not passing
$formby reference. This is essential to make changes to the variable. Variables can be passed by reference by prepending them with an ampersand (&$form). This is explained in the PHP manual: PHP: Passing by reference, and also in the API documentation for hook_form_FORM_ID_alter().Secondly, you are not using the hook as described in the API, you should have three arguments:
&$form,&$form_stateand$form_id. For your example this has no impact on the working, but this indicates that you are not using the hooks correctly. Please read up on Understanding the hook system for Drupal modules.Thirdly, you should definitely not set
'#action'to' '. Most of the time you should not change this property as it will break the submitting of the form.On a side note, please don't raise the priority of your ticket to "critical". This is reserved for really serious problems. Support tickets should always have the "normal" priority. Raising the priority actually has an adverse effect because people tend to avoid critical support tickets, as it is considered to be bad form.
I'm going to close this issue again as "works as designed". It is really out of scope of the issue queue to teach you how to use Drupal, and doing it this way will be a very slow process :) I can recommend you to take a look at the Examples module, and to read the online documentation, or read some of the excellent books on the topic. Good luck!
Comment #6
roynilanjan commentedI tried with even reference variable
and in the search_submit call back there is a $form_state['redirect'] that was not working until & unless $form['#action'] = ' '; in above mentioned function..
If you think I need to open a different thread i'll open but it should have an proper explanation ;)
Comment #7
pfrenssenDo you want the original callback (
search_form_submit()) to still be executed? That also does a redirect and will run before yoursearch_submit()callback as you are adding yours after the original one.Comment #8
roynilanjan commentedprobably I have got a clue from your question why action needs to blank in the scenario I mentioned before!
so when I make action='' then default callback(search_form_submit()) will not be executed only
$form['submit'][] = search_submit() called up...
Comment #9
pfrenssenTry this:
Comment #10
roynilanjan commentedNotice the empty brackets at the end of the $form['#submit'][]. This will append your new submit hook to the end of the array, instead of overwriting it with a string.
So if given $form['#submit'] haven't worked for me as well! Please have a look
http://drupal.org/node/1054728
Comment #11
pfrenssenMy example is not overwriting it with a string, but is replacing the entire array with a new one containing only your callback. I thought you wanted to prevent the original submit callback from executing. If this is not the case I'm afraid I'm still not understanding what you are trying to accomplish.
Comment #12
roynilanjan commentedPlease don't be afraid :)
here is my expected debug,
#submit (Array, 2 elements)
0 (String, 18 characters ) search_form_submit | (Callback) search_form_submit();
1 (String, 29 characters ) form_handler_mysubmit_handler | (Callback) form_handler_mysubmit_handler();
want to use both the callbacks that's why extra [] for extra dimension in array.
but the action = '' it seems to me as I have panel implementation ... and search block is in my panel might be there some difference ...other-wise normal drupal it's not expected behavior...