I've created a form that is loaded with ajax when clicking on a button, but the form validation doesn't work (and so is my custom submit function). The regular (Drupal's) form validation did work when I used MENU_NORMAL_ITEM and entered the form to a test page, but now when I'm using the current code it's not working.

  • I guess that when I'll manage to "fix" Drupal's form validation I'll also be able to use my custom submit function.

My code:

function MYMODULE_menu() {
  $items['ajax/my_ajax_page'] = array(
      'title' => 'My title',
      'page callback' => 'MYMODULE_my_ajax_callback',
      'type' => MENU_CALLBACK,
      'access arguments' => array('access content'),

  return $items;

function MYMODULE_my_ajax_callback() {
  print render(drupal_get_form('my_form'));



Well im not so sure about exiting...

i would try in my ajax callback:

function MYMODULE_my_ajax_callback() {
  $commands = array();
  $form = drupal_get_form('my_form');
  // im doing a replace command as an example, this could be another command invoked..
  $commands[] = ajax_command_replace('#container-to-append-form', render($form));

  $page = array('#type' => 'ajax', '#commands' => $commands);
| improve this answer | |

Your Answer

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

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