0

I have written a custom module for form submission the first time but submit button is not working.

Here is the code:

function my_form($form, &$form_state) {

$node = array();
$pl_name=array();
$pl_name=getplaylist_to_edit(arg(1));


$node['text'] = array(
'#type' => 'textfield',
'#id'=>'edit-playlist-name',
'#value' => $pl_name[1],
);

$node['submit'] = array(
'#type' => 'submit',
'#value' => 'Update',
'#submit' => array('test'),
);

return $node;
}


function test()
{
echo '<script>alert("You have submitted the form.");</script>';
}
3
  • 1
    I'm not sure but I think the variable name could be important: $form instead of $node (because of the parameters).
    – Djouuuuh
    Commented Oct 1, 2014 at 13:34
  • 1
    Has something led you to believe that randomly echoing something in the middle of a request will do anything at all?
    – Clive
    Commented Oct 1, 2014 at 13:49
  • Just to check whether the function is being called or not the alert is echoing.
    – D-pak
    Commented Oct 2, 2014 at 4:19

2 Answers 2

0

Could you try like this:

function my_form($form, &$form_state) {
  $pl_name=array();
  $pl_name=getplaylist_to_edit(arg(1));

  $form['text'] = array(
    '#type' => 'textfield',
    '#id'=>'edit-playlist-name',
    '#value' => $pl_name[1],
  );

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

  return $node;
}

function my_form_submit($form, &$form_state){
  echo '<script>alert("You have submitted the form.");</script>';
}
1
  • Yes, I had tried it but same problem. Function is not being called.
    – D-pak
    Commented Oct 2, 2014 at 4:23
0

I just ran something similar to your callback function in my local test enviroment. For me the function was getting called, the echo/print wasn't doing anything. Try using a drupal_set_message('you have submitted the form'); in stead of echoing out the java call to see if that gets fired.

I'm not 100% sure on this, but I THINK the reason this is happening is due to a redirect or page refresh that's happening after your submit function is called. That would wipe away anything you echo or print out from that function. As a general rule, it's probably best to stick with ether drupal_set_message to print messages out to the user, or download and install devel and use dsm() to print out test messages.

1
  • Not even page refresh process is happening.
    – D-pak
    Commented Oct 2, 2014 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.