Please have a look the situation,

$form['#action'] = ' ';
  $form['#submit'][] = 'search_submit';

now until & unless I nullified the action parameter submit handler callback is not working.
Can you please tell me regard that!

Comments

pfrenssen’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Hello, 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.

roynilanjan’s picture

Status: Postponed (maintainer needs more info) » Needs review

Above 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)


mymodule_form_alter($form) {
$form['#action'] = ' ';
$form['#submit'][] = 'search_submit';
}

function search_submit($form,$form_state) {

 //some logic
}

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

pfrenssen’s picture

Status: Needs review » Closed (works as designed)

I'm sorry but your code does not make much sense. You are probably using the wrong hook. Your code will alter all forms, sets #action to 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 like mymodule_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().

roynilanjan’s picture

Priority: Normal » Critical
Status: Closed (works as designed) » Needs review

Yes code should be under hook_form_FORMID_alter() or under a specific form id in a hook_form_alter().

function module_form_search_form_alter($form) {

  $form['#action'] = ' ';
  $form['#submit'][] = 'search_submit';

}

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 :)

pfrenssen’s picture

Priority: Critical » Normal
Status: Needs review » Closed (works as designed)

If 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 $form by 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_state and $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!

roynilanjan’s picture

Status: Closed (works as designed) » Active

I tried with even reference variable

function module_form_search_form_alter(&$form,&form_state,$form_id) {

  $form['#action'] = ' ';
  $form['#submit'][] = 'search_submit';

}

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

pfrenssen’s picture

Do you want the original callback (search_form_submit()) to still be executed? That also does a redirect and will run before your search_submit() callback as you are adding yours after the original one.

roynilanjan’s picture

probably 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...

pfrenssen’s picture

Try this:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function module_form_search_form_alter(&$form, &form_state, $form_id) {
  // Replace the original submit callback with our own.
  $form['#submit'] = array('search_submit');
}
roynilanjan’s picture

Notice 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

pfrenssen’s picture

My 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.

roynilanjan’s picture

Please 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...

Version: 7.19 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.