/* implementation of function intelligentsystem_menu(){
....
}*/

function intelligent_system_home_output(){
header('Content-type: text/plain; charset=UTF-8');
header('Content-Disposition: inline');
$content = intelligent_system_home_nameform();
return $content;

}

function intelligent_system_home_nameform(){

$form['title'] = array(
'#type' => 'fieldset',
'#title' => t('Enter the information :'),
);

$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name :'),
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);

$form['#submit'] = 'intelligent_system_home_nameform_submit';
return $form;
}

function intelligent_system_home_nameform_submit($form, &$form_state) {
drupal_set_message(t('The data is being Analyzed!!'));
}

I have tried calling a user defined function also rather than the above mentioned _submit..but nothing is working..drupal 6 used to support the above...but drupal 7 doesnt seem to..have checked out many forums..but there seems to be no solution..pls help..

Comments

Bagz’s picture

Not sure what the line

$form['#submit'] = 'intelligent_system_home_nameform_submit';

is doing in your code. Any form attributes must be declared as arrays, here you are declaring it as a string. Take it out and see if it helps.

mdorrell’s picture

What Bagz means is you can fix this by changing

$form['#submit'] = 'intelligent_system_home_nameform_submit';
to
$form['#submit'][] = 'intelligent_system_home_nameform_submit';

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.

drupal.hobby’s picture

hey did u find any solution.
I am migrating my module from D6 to D7.
I am also facing the the same problem.

I have given:
$form['#submit'] = array('intelligent_system_home_nameform_submit') ;

Let me know what worked for you.

shafiul’s picture

This worked for me:

$form['#submit'][] = 'charity_addRole';

Later:

function charity_addRole($form){
    dsm($form);
}
mr_druppa’s picture

By writing this:

$form['#submit'] = array('intelligent_system_home_nameform_submit') ;

you could be potentially overwriting other modules addition to the '#submit' array, that means their callbacks won't be fired anymore...it's better to add to the array instead:

$form['#submit'][] = 'intelligent_system_home_nameform_submit';

salimshaik’s picture

Hey try this below code:

$form['#submit'] [] = 'intellegent_system_home_nameform_submit';

check this above code..now

mensfort’s picture

For me, I added another field to the form button:

you have
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);

I have:
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#submit' => array('reset_your_pc'),
);

jerilcjs’s picture


function customsite_form_alter(&$form, &$form_state, $form_id) 
{
        //dsm($form_id); - prints the name of the form, once the devel module is enabled
        switch($form_id)
	{
            case 'name_of_the_form': //get the name of the form using the above dsm($form_id)
               $form['#submit'][] = 'test_form_submit';
               break;
        }
}

function test_form_submit($form, &$form_state)
{
     drupal_set_message("How are you");
}


jerilcjs’s picture

//this will work for all submit buttons
$form['#submit'][] = 'test_form_submit';

If you want custom handler for submit button, applychanges button and delete button. Find the name of your buttons using devel.

array_unshift($form['actions']['submit']['#submit'], 'test_form_submit_1');
array_unshift($form['actions']['applychanges']['#submit'],'test_form_submit_2');
array_unshift($from['actions']['delete']['#submit'],'test_form_submit_3');
			 
or

$form['actions']['submit']['#submit'][0] = 'asset_form_submit';

use array_unshift for not getting clobbered..!

then finally

function test_form_submit_1($form, &$form_state)
{
   drupal_set_message("Hello");	
}

richardp’s picture

I am also having this problem; I just don't see what I am doing wrong. I've been a D6 programmer for years, and after reading numerous articles for D7, I can't figure it out. Here's my super-simple code:

function tc_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "tracking_code_node_form") {    
    // Add in our custom submit handler.
    $form["#submit"][] = "tc_test";
  }
}

function tc_test($form, &$form_state) {
  drupal_set_message("here");
}

Can anyone tell me what I am doing wrong? I never get into that function. And I have confirmed that hook_form_alter is indeed attaching that submit handler to the correct form ;)

Thanks!

richardp’s picture

And of course I figure out my problem literally seconds after posting this. It never fails, does it?

Anyway, I WAS getting into that function, but I wasn't seeing the message. When I did a watchdog() call instead, I saw it show up in the database!

I logged out and back in, and suddenly the message is now showing up. I guess something was screwy with my session?

Anyway, sorry-- the code I posted DOES work.

Richard

Ali Sheikh’s picture

HI!
How Can I Submit My Form In Drupal

michaellenahan’s picture

I had the same problem, I was wondering why my submit handler was not firing.
My usual helpers dpm('hello'); and var_dump('hello'); were not showing up.
Then tried dd('hello');, and sure enough it showed up in /tmp/drupal_debug.txt
For anyone coming across this - dd() or drupal_debug() should work as long as you have devel module enabled.

hkirsman’s picture

$form['fb_fan_general_settings']['is_edit'] = array(
    '#type' => "hidden",
    '#required' => TRUE,
    '#default_value' => $is_edit,
);

$is_edit is boolean, so when it's TRUE, #default_value gets empty string.

And because it was hidden, I could not see the error.

Proper way:

$form['fb_fan_general_settings']['is_edit'] = array(
    '#type' => "textfield",
    '#required' => TRUE,
    '#default_value' => $is_edit ? '1' : '0',
  );
Smaug’s picture

I struggled to get this working too in a .module file. You have to have both the button and the '#submit' part, and then define the redirect in the submit function.

  $form['submit'] = array(
	'#type' => 'submit',
	'#value' => t('Submit'),
  );

  $form['#submit'][] = 'sdrn_join_joinup_submit';
function my_module_myform_submit($form, &$form_state) {

	$form_state['redirect'] = 'http://www.google.co.uk/';

}

The documentation lead me to believe that the _submit function would be automatically picked up, but this didn't seem to be the case:

Any forms which are submitted from a button of type => 'submit' will be passed to their corresponding submit function if it is available.

Perhaps there was something else going on in my form breaking it though.

makbeta’s picture

I figured this out after looking at the source code of entity forms.
Instead of putting the callback under #submit, put it under actions.
So instead of this:
$form["#submit"][] = "tc_test";
Try this:
$form['actions']['submit']["#submit"][] = "tc_test";

It worked for me, hopefully is saves someone else some headache.

mirakolous’s picture

I had the same problem only on an entity form and this solved it.

manish9a9’s picture

If you are rendering your form using form--anyformname.tpl.php template file then make sure in that template file you are rendering these three thing at the end:

print render($form['form_id']);
print render($form['form_build_id']);
print render($form['form_token']);
halth’s picture

Hey guys!

@manish9a9's answer was totally the case with me.

Make sure that if you're using a template file to theme your form, you don't forget to place:

  print drupal_render_children($form);

anywhere on your template file.

This will render the missing items (usually the tokens) to your form and make sure it gets properly processed/executed.

Thank you and good luck! ;)

--
Heitor Althmann
Drupal Developer

sirusdas’s picture

I have spend days to get to this. Thanks a lot.

inascon’s picture

If one of the submit handlers performs a batch operation, all subsequent submit handlers will not be called anymore.