I have a form defined

function form_igallery(){

	$form=Array (
		'#attributes' => array('enctype' => "multipart/form-data"),
		'upload'=>Array(
			'#type'=>'fieldset',
			'#title'=>'Upload Images',
			'#description' => 'Click to expand.',
			'#collapsible'=>1,
			'#collapsed'=>1,
			'photo1'=>Array(
				'#type'=>'file',
				'#title'=>'Upload First Photo',
			),
			'caption1'=>Array(
				'#type'=>'textfield',
				'#title'=>t('Caption'),
				'#description'=>t('Add a Caption if desired.'),
				'#maxlength'=>128
			),
			'group1'=>Array(
				'#type'=>'textfield',
				'#title'=>t('Group'),
				'#description'=>t('You can group photos together.'),
				'#maxlength'=>64
			),
			'submit'=>Array(
				'#type' => 'button', 
				'#value' => t('Upload')
			)
		),
	);
	$form['#submit'][0]='form_igallery_submit';
	return $form;
}

I am expecting this: $form['#submit'][0]='form_igallery_submit'; array element to call the following function when the submit button is clicked:


function form_igallery_submit($form, &$form_state){
	drupal_set_message('Processing files....');
}

But as far as I can tell this does not happen.

Can anyone see my error?

Comments

cignex’s picture

Hello,

Can you try with my code???


            'submit'=>Array(
                '#type' => 'button',
                '#value' => t('Upload'),
                '#executes_submit_callback' => TRUE,
            )

I have added one line in array of submit and this line of code is '#executes_submit_callback' => TRUE .

Please try this.

davecoventry’s picture

Much to my surprise!

Thank you!

damianrr’s picture

Hi,

I tried all the suggestions here and others, and i still can't get the _submit to work, execution never gets there, i am tearing my hair out, any ideas about what's going on here?

function recipebox_nodeapi(&$node, $op, $teaser, $page) {
  
  switch ($op) {
    case 'view':
      global $user;
      if ($teaser || $user->uid == 0) {
        break;
      }

      $res = db_query('SELECT nid, uid FROM {recipebox} WHERE nid = %d AND uid = %d LIMIT 1', $node->nid, $user->uid);
      $item = db_fetch_object($res);

      $type = node_get_types('type', $node);
      if ($type->orig_type != 'recipe') {
        break;
      }

       if ($item == false) {
        $node->content['box_form'] = array (
          '#value' => drupal_get_form('box_form', $node, $user, "add"),
          '#weight' => 20,
        );
      }
      else
      {
        $node->content['box_form'] = array(
          '#value' => drupal_get_form('box_form', $node, $user, "delete"),
          '#weight' => 20,
        );
      }

  }

}

function box_form($context, $node, $user, $operation) {
  $message = "";
  if ($operation == "add") {
    $message = "Add to recipe's box";
  }
  elseif ($operation == "delete") {
    $message = "Delete from recipe's box";
  }

  $form = Array (
    'operation' => Array ( '#type' => 'value', '#value' => $operation, ),
    'node' => Array ( '#type' => 'value', '#value' => $node, ),
    'user' => Array ( '#type' => 'value', '#value' => $user, ),
    'submit' => Array( '#type' => 'button', '#value' => $message, '#executes_submit_callback' => TRUE, /*'#redirect' => drupal_get_form('box_form_submit'),*/  ),
  );

  $form['#submit'][0]='box_form_submit';
  return $form;
}

function box_form_submit($form, &$form_state) {
  drupal_set_message("hello!");
   die("Break the exec!!");
}
ecstasy2’s picture

Try this instead:

'submit'=>Array(
                '#type' => 'submit', 
                '#value' => t('Upload')
            )

You need to set the type to submit.

davecoventry’s picture

I really have been tearing my hair out over this one.

I couldn't see what I was doing wrong.

Thanks again, to both of you.

damianrr’s picture

Hi,

I tried all the suggestions posted here and others, and i still can't get the _submit to work, when i click the button it just reload the page, execution never gets there (box_form_submit), i am tearing my hair out, any ideas about what's going on here?


function recipebox_nodeapi(&$node, $op, $teaser, $page) {
 
  switch ($op) {
    case 'view':
      global $user;
      if ($teaser || $user->uid == 0) {
        break;
      }

      $res = db_query('SELECT nid, uid FROM {recipebox} WHERE nid = %d AND uid = %d LIMIT 1', $node->nid, $user->uid);
      $item = db_fetch_object($res);

      $type = node_get_types('type', $node);
      if ($type->orig_type != 'recipe') {
        break;
      }

       if ($item == false) {
        $node->content['box_form'] = array (
          '#value' => drupal_get_form('box_form', $node, $user, "add"),
          '#weight' => 20,
        );
      }
      else
      {
        $node->content['box_form'] = array(
          '#value' => drupal_get_form('box_form', $node, $user, "delete"),
          '#weight' => 20,
        );
      }

  }

}

function box_form($context, $node, $user, $operation) {
  $message = "";
  if ($operation == "add") {
    $message = "Add to recipe's box";
  }
  elseif ($operation == "delete") {
    $message = "Delete from recipe's box";
  }

  $form = Array (
    'operation' => Array ( '#type' => 'value', '#value' => $operation, ),
    'node' => Array ( '#type' => 'value', '#value' => $node, ),
    'user' => Array ( '#type' => 'value', '#value' => $user, ),
    'submit' => Array( '#type' => 'button', '#value' => $message, '#executes_submit_callback' => TRUE, /*'#redirect' => drupal_get_form('box_form_submit'),*/  ),
  );

  $form['#submit'][0]='box_form_submit';
  return $form;
}

function box_form_submit($form, &$form_state) {
  drupal_set_message("hello!");
   die("Break the exec!!");
}

n3_nash’s picture

Drupal 7:

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