1

I have custom form created with Form API.

<?php
function myform($form, &$form_state) {

//some form elements..
$form['#action'] = '/my-projects';
 $form['#submit'] = array('myform_submit');
return $form;
 }
?>

I have a problem, that my submit function is not called. I need to comment line with $form['#action'], and then my submit function works. But problem is, that I need to set action manually. (My form is loaded with ajax on javascript event, and loaded form has set the #action parameter by system according last called page URL.

In particular, I am rendering the form with jquery $.get method. $.get returns HTML output of the form. But the problem is, it returns form with action set to

<form action= "/my-ajax-path">

, where "my-ajax-path" is path used in $.get method to render the form, but I dont want Drupal to set this path IN rendered form. Thats why I am trying to set #action manually.

How can I let work #action and #submit parameter together?

  • 1
    Presumably '/my-projects' is a Drupal path you've defined with hook_menu()? – Clive Dec 4 '13 at 15:06
  • Well of course if you manually specify where the data should go (with action), you are overriding any automated submit handling. I smell XY problem: you want to achieve X, you think Y is the way, so you ask us how to make Y work, instead of asking us how to achieve X. – Mołot Dec 4 '13 at 15:13
  • @Clive: Yes, the path is defined with hook_menu – tomas.teicher Dec 5 '13 at 5:20
  • @Molot: ok, so how to achieve X? I thought that submit handlers are registered when the form is rendered, so they can be called after submission regardless on action path. So the form submit handlers are called and then the requested page is rendered. Ok, when it doesn't work like this, can I somehow attach form submit handlers to particular path, while the form is not rendered on this path (form is rendered only on ajax call) ? – tomas.teicher Dec 5 '13 at 5:28
  • 1
    But what is X? You can send your data to the default patch, and use $form_state['redirect'] if you want to display another page after things gets processed. – Mołot Dec 5 '13 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.