0

I updated my post up top to pull in the user form created in Drupal, it now loads it in a lightbox correctly, how can I submit this using AJAX, validate this all in the Lightbox? any ideas?

Any help would be good help :)

    <?php
function ajax_register_menu() {
  $items['request'] = array(
    'page callback' => 'ajax_register_mypage',
    'page arguments' => array('ajax_register_form'),
    'type' => MENU_CALLBACK,
    'access callback' => TRUE,
    'title' => t('MY TITLE'),
  );

  $items['request/submit'] = array(
    'page callback' => 'ajax_register_submit',
    'type' => MENU_CALLBACK,
    'access callback' => FALSE,
  );

  return $items;
}

function ajax_register_mypage($form){
    print '<div style="background: #FFFFFF;">';
    print 'Hello World';
    print render(drupal_get_form('user_register_form'));
    print '</div>';
}

function ajax_register_submit() {
    $returnO = new StdClass();
    $returnO->status = true;
    $returnO->message = 'MY INFORMATIVE MESSAGE HERE';

    print drupal_json($returnO);

    die;
}
?>

1 Answer 1

0

If I recall correctly, instead of calling render() for your drupal_get_form(), call drupal_render() instead.

<?php 

function ajax_register_mypage($form){
  print 'Hello World';
  print drupal_render(drupal_get_form($form));
}

?>

Hope this ends up solving your issue on this one.

2
  • render() is just a wrapper that calls drupal_render() internally. The only difference is that render() checks to see if the argument is an array. If so, it passes through drupal_render(), if not it just returns the variable as-is. using either function on a form array will produce exactly the same results
    – Clive
    Commented Apr 19, 2012 at 23:59
  • I updated my post up top to pull in the user form created in Drupal, it now loads it in a lightbox correctly, how can I submit this using AJAX, validate this all in the Lightbox? any ideas?
    – Sukh
    Commented Apr 20, 2012 at 14:01

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.